Skip to content

Commit eb043d9

Browse files
committed
feat(sqlalchemy): organized provisioning for tests
1 parent 8e09861 commit eb043d9

File tree

16 files changed

+302
-181
lines changed

16 files changed

+302
-181
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ playground.ipynb
1818

1919
src/tests/assets/*-shm
2020
src/tests/assets/*-wal
21+
22+
chinook.sqlite

bandit-baseline.json

Lines changed: 132 additions & 108 deletions
Large diffs are not rendered by default.

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ bandit==1.7.1
1818
# this package is only used for testing compatibility
1919
# with pandas dataframe
2020
pandas>=1.1.5
21+
SQLAlchemy>=1.4.53

sqlalchemy-sqlitecloud/README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
# SQLite Cloud dialect for SQLAlchermy (beta)
1+
# SQLite Cloud Dialect for SQLAlchemy (Beta)
22

3-
This package makes SQLAlchemy to work with SQLite Cloud.
3+
This package enables SQLAlchemy to work seamlessly with SQLite Cloud. The dialect is built upon the existing `sqlite` dialect in SQLAlchemy.
44

5-
The dialect is based on the `sqlite` dialect included in SQLAlchemy.
5+
## Beta Version
66

7-
## Beta version
7+
This dialect is in its early stages and is compatible with Python >= 3.6.
88

9-
This dialect is an early version and it works on Python >= 3.6.
9+
**Note:** It has been tested only `SQLAlchemy 1.4`.
1010

11-
**Tested only on `Python 3.6` and `SQLAlchemy 1.4`.**
11+
The dialect has undergone testing against the SQLAlchemy `test_suite`, as outlined in the [official documentation](https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4_53/README.dialects.rst).
1212

13-
The dialect as been tested against the SQLAlchemy `test_suite` as reported in the [documentation](https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4_53/README.dialects.rst).
13+
You can track the progress of the remaining test issues [in this issue](https://github.com/sqlitecloud/sqlitecloud-py/issues/21#issuecomment-2305162632).
1414

15-
You can follow the status of the tests that are still failing [in the dedicated issue](https://github.com/sqlitecloud/sqlitecloud-py/issues/21#issuecomment-2305162632).
15+
_The same tests failed and passed on both Python 3.6 and Python 3.11._
1616

17-
References:
18-
- [Official SQLAlchemy documentation](https://docs.sqlalchemy.org/en/14/index.html)
19-
- [https://www.sqlalchemy.org/](https://www.sqlalchemy.org/)
17+
## References
2018

19+
- [SQLAlchemy Documentation](https://docs.sqlalchemy.org/en/14/index.html)
20+
- [SQLAlchemy Official Website](https://www.sqlalchemy.org/)
2121

22-
# Install and Usage
22+
## Installation and Usage
23+
24+
To install the package, use the following command:
2325

2426
```bash
2527
$ pip install sqlalchemy-sqlitecloud
2628
```
2729

28-
> Get your SQLite Cloud connection string from the SQLite Cloud dashboard or register on [sqlitecloud.io](https://sqlitecloud.io) to get one.
30+
> Get your SQLite Cloud connection string from the SQLite Cloud dashboard, or register at [sqlitecloud.io](https://sqlitecloud.io) to get one.
2931
30-
Create the SQLAlchemy engine by setting the SQLite Cloud connection string. Add the prefix `sqlite+` like:
32+
Create an SQLAlchemy engine using the SQLite Cloud connection string::
3133

3234
```python
3335
from sqlalchemy import create_engine
3436

35-
engine = create_engine('sqlite+sqlitecloud://mynode.sqlite.io?apikey=key1234')
37+
engine = create_engine('sqlitecloud://mynode.sqlite.io?apikey=key1234')
3638
```
3739

3840

3941
# Run the Test Suite
4042

41-
Install the `sqlitecloud` package with:
43+
To run the test suite, first install the sqlitecloud package:
4244

4345
```bash
4446
$ pip install sqlitecloud # last version
@@ -51,20 +53,24 @@ $ cd ../src # sqlitecloud src directory
5153
$ pip install -e .
5254
```
5355

54-
Run the test suite with:
56+
Then, run the test suite with:
5557

5658
```bash
5759
$ cd sqlalchemy-sqlitecloud
5860
$ pytest
5961
```
6062

61-
> Note: VSCode Test Explorer and VSCode GUI debugger doesn't work because the actual implementation
62-
is not in the `test/test_suite.py` file. It cannot find the tests source code in the third-parties directory.
63+
> Note: VSCode Test Explorer and VSCode GUI debugger doesn't work because the actual implementation of tests
64+
is not in the `test/test_suite.py` file. The test source code is located in a third-party directory and it's not recognized.
65+
66+
For command-line debugging, use `pytest --pdb` with `pdb.set_trace()`.
6367

64-
Use `pytest --pdb` with `pdb.set_trace()` to debug with command line:
68+
Some useful `pdb` commands include:
6569

6670
- `s` step into
6771
- `n` next line
6872
- `r` jump to the end of the function
6973
- `c` continue
70-
- `a` print all variables
74+
- `w` print stack trace
75+
76+
More info: [https://docs.python.org/3/library/pdb.html](https://docs.python.org/3/library/pdb.html)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sqlitecloud # latest

sqlalchemy-sqlitecloud/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ profile_file=test/profiles.txt
88

99
[db]
1010
# SQLite Cloud connection string is set in conftest.py with testing apikey
11-
#default=sqlite+sqlitecloud://...
11+
default=sqlitecloud://placeholder.sqlite.io

sqlalchemy-sqlitecloud/setup.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
entry_points = {
2-
"sqlalchemy.dialects": [
3-
"sqlite.cloud = sqlalchemy_sqlitecloud.base:SQLiteCloudDialect",
4-
]
5-
}
1+
from pathlib import Path
2+
3+
from setuptools import find_packages, setup
4+
5+
long_description = (Path(__file__).parent / "README.md").read_text()
6+
7+
setup(
8+
name="sqlalchemy-sqlitecloud",
9+
version="0.1.0",
10+
author="sqlitecloud.io",
11+
description="SQLAlchemy Dialect for SQLite Cloud.",
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
url="https://github.com/sqlitecloud/sqlitecloud-py",
15+
packages=find_packages(),
16+
install_requires=[
17+
"sqlitecloud",
18+
],
19+
keywords="SQLAlchemy SQLite Cloud",
20+
classifiers=[
21+
"Development Status :: 3 - Alpha",
22+
"Intended Audience :: Developers",
23+
"License :: OSI Approved :: MIT License",
24+
"Programming Language :: Python :: 3.6",
25+
"Programming Language :: Python :: 3.7",
26+
"Programming Language :: Python :: 3.8",
27+
"Programming Language :: Python :: 3.9",
28+
"Programming Language :: Python :: 3.10",
29+
"Programming Language :: Python :: 3.11",
30+
"Programming Language :: Python :: 3.12",
31+
],
32+
license="MIT",
33+
entry_points={
34+
"sqlalchemy.dialects": [
35+
"sqlitecloud = sqlalchemy_sqlitecloud.base:SQLiteCloudDialect",
36+
]
37+
},
38+
)
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from sqlalchemy.dialects import registry
2-
3-
registry.register(
4-
"sqlite.sqlitecloud", "sqlalchemy_sqlitecloud.base", "SQLiteCloudDialect"
5-
)

sqlalchemy-sqlitecloud/sqlalchemy_sqlitecloud/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def result_processor(self, dialect, coltype):
3535

3636

3737
class SQLiteCloudDialect(SQLiteDialect):
38+
name = "sqlitecloud"
39+
driver = "sqlitecloud"
40+
3841
default_paramstyle = "qmark"
3942
supports_statement_cache = False
4043

@@ -46,8 +49,6 @@ class SQLiteCloudDialect(SQLiteDialect):
4649
},
4750
)
4851

49-
driver = "sqlitecloud"
50-
5152
@classmethod
5253
def dbapi(cls):
5354
from sqlitecloud import dbapi2
@@ -104,8 +105,8 @@ def create_connect_args(self, url: URL):
104105
"SQLite Cloud URL is required.\n"
105106
"Register on https://sqlitecloud.io/ to get your free SQLite Cloud account.\n"
106107
"Valid SQLite Cloud URL are:\n"
107-
" sqlite+sqlitecloud:///myuser:mypass@myserver.sqlite.cloud/mydb.sqlite?non_linearizable=true\n"
108-
" sqlite+sqlitecloud:///myserver.sqlite.cloud/?apikey=mykey1234"
108+
" sqlitecloud:///myuser:mypass@myserver.sqlite.cloud/mydb.sqlite?non_linearizable=true\n"
109+
" sqlitecloud:///myserver.sqlite.cloud/?apikey=mykey1234"
109110
)
110111

111112
# TODO: this should be the list of SQLite Cloud Config params

sqlalchemy-sqlitecloud/sqlalchemy_sqlitecloud/provision.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
3+
from dotenv import load_dotenv
4+
from sqlalchemy.engine import make_url
15
from sqlalchemy.pool import Pool
26
from sqlalchemy.testing.provision import (
37
generate_driver_url,
@@ -11,13 +15,22 @@
1115
}
1216

1317

14-
@generate_driver_url.for_db("sqlite")
18+
@generate_driver_url.for_db("sqlitecloud")
1519
def generate_driver_url(url, driver, query_str):
16-
# eg: sqlite+sqlitecloud://mynode.sqlite.cloud/sqlalchemy_cloud.db?apikey=key123
17-
return url
20+
# no database specified here, it's created and used later
21+
# eg: sqlitecloud://mynode.sqlite.cloud/?apikey=key123
22+
23+
load_dotenv("../../.env")
24+
25+
connection_string = os.getenv("SQLITE_CONNECTION_STRING")
26+
apikey = os.getenv("SQLITE_API_KEY")
27+
28+
connection_string += f"?apikey={apikey}"
29+
30+
return make_url(connection_string)
1831

1932

20-
@post_configure_engine.for_db("sqlite")
33+
@post_configure_engine.for_db("sqlitecloud")
2134
def _sqlite_post_configure_engine(url, engine, follower_ident):
2235
from sqlalchemy import event
2336

@@ -48,11 +61,11 @@ def _create_dbs(url, database):
4861
)
4962

5063

51-
@stop_test_class_outside_fixtures.for_db("sqlite")
64+
@stop_test_class_outside_fixtures.for_db("sqlitecloud")
5265
def stop_test_class_outside_fixtures(config, db, cls):
5366
db.dispose()
5467

5568

56-
@temp_table_keyword_args.for_db("sqlite")
69+
@temp_table_keyword_args.for_db("sqlitecloud")
5770
def _sqlite_temp_table_keyword_args(cfg, eng):
5871
return {"prefixes": ["TEMPORARY"]}

0 commit comments

Comments
 (0)