Skip to content

Commit e1545a0

Browse files
committed
fix: code review
1 parent 7b45a51 commit e1545a0

7 files changed

Lines changed: 39 additions & 9 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: uv sync --all-extras
2727

2828
- name: Run tests
29-
run: uv run pytest
29+
run: uv run pytest -m "not integration"
3030

3131
- name: Build package
3232
run: uv build

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ clean:
2222
rm -rf dist
2323

2424
local-install: clean build
25-
pip install ./dist/datashield-*.tar.gz
25+
pip install ./dist/datashield_opal-*.tar.gz
2626

2727
local-install-force: clean build
28-
pip install ./dist/datashield-*.tar.gz --break-system-packages
28+
pip install ./dist/datashield_opal-*.tar.gz --break-system-packages

datashield_opal/impl.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def assign_table(
8888
.query("async", asynchronous)
8989
)
9090
if variables is not None:
91-
builder.query("variables", f'name.any("{",".join(variables)}")')
91+
vars = ",".join([f'"{v}"' for v in variables])
92+
builder.query("variables", f"name.any({vars})")
9293
if identifiers is not None:
9394
builder.query("identifiers", identifiers)
9495
if id_name is not None:
@@ -191,8 +192,8 @@ def list_packages(self) -> list:
191192
def format_method(x):
192193
return f"{x['pkg']}:{x['version']}" if "pkg" in x and "version" in x else None
193194

194-
aggregate = [format_method(x) for x in aggregate if "pkg" in x]
195-
assign = [format_method(x) for x in assign if "pkg" in x]
195+
aggregate = [x for x in [format_method(x) for x in aggregate] if x is not None]
196+
assign = [x for x in [format_method(x) for x in assign] if x is not None]
196197

197198
# unique values
198199
pkgs = list(set(aggregate + assign))
@@ -240,7 +241,7 @@ def rm_workspace(self, name: str) -> list:
240241
def is_async(self) -> dict:
241242
return {"aggregate": True, "assign_table": True, "assign_resource": True, "assign_expr": True}
242243

243-
def keep_alive(self) -> bool:
244+
def keep_alive(self) -> None:
244245
with suppress(Exception):
245246
self.list_symbols()
246247

@@ -279,7 +280,7 @@ def _get_session(self):
279280
if response.code == 201:
280281
self.session = response.from_json()
281282
else:
282-
raise OpalDSError(ValueError("DataSHIELD session creation failed: " + response.code))
283+
raise OpalDSError(ValueError(f"DataSHIELD session creation failed: {response.code}"))
283284
return self.session
284285

285286
def _get(self, ws) -> OpalRequest:

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ Repository = "https://github.com/datashield/datashield-opal-python"
4141
Documentation = "https://datashield.github.io/datashield-opal-python"
4242
"Bug Tracker" = "https://github.com/datashield/datashield-opal-python/issues"
4343

44+
[tool.pytest.ini_options]
45+
markers = [
46+
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
47+
]
48+
4449
[build-system]
4550
requires = ["hatchling"]
4651
build-backend = "hatchling.build"
4752

4853
[tool.hatch.build.targets.wheel]
49-
packages = ["datashield"]
54+
packages = ["datashield_opal"]

tests/test_api_admin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datashield import DSSession, DSLoginBuilder
2+
import pytest
23

34

45
class TestClass:
@@ -16,32 +17,38 @@ def setup_class(cls):
1617
def teardown_class(cls):
1718
cls.session.close()
1819

20+
@pytest.mark.integration
1921
def test_profiles(self):
2022
rval = self.session.profiles()
2123
assert "server1" in rval
2224
assert rval["server1"]["current"] == "default"
2325
assert len(rval["server1"]["available"]) > 0
2426

27+
@pytest.mark.integration
2528
def test_packages(self):
2629
rval = self.session.packages()
2730
print(rval)
2831
assert True
2932

33+
@pytest.mark.integration
3034
def test_methods(self):
3135
rval = self.session.methods()
3236
print(rval)
3337
assert True
3438

39+
@pytest.mark.integration
3540
def test_tables(self):
3641
rval = self.session.tables()
3742
print(rval)
3843
assert True
3944

45+
@pytest.mark.integration
4046
def test_resources(self):
4147
rval = self.session.resources()
4248
print(rval)
4349
assert True
4450

51+
@pytest.mark.integration
4552
def test_workspaces(self):
4653
rval = self.session.workspaces()
4754
print(rval)

tests/test_api_analysis.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from datashield import DSSession, DSLoginBuilder, DSError
23

34

@@ -13,6 +14,7 @@ def setup_method(self, method):
1314
def teardown_method(self, method):
1415
self.session.close()
1516

17+
@pytest.mark.integration
1618
def test_assign_tables(self):
1719
try:
1820
self.session.assign_table(
@@ -28,6 +30,7 @@ def test_assign_tables(self):
2830
print(self.session.get_errors())
2931
raise ValueError("Failed to assign tables") from e
3032

33+
@pytest.mark.integration
3134
def test_assign_table(self):
3235
try:
3336
self.session.assign_table("df", table="CNSIM.CNSIM1", asynchronous=False)
@@ -41,6 +44,7 @@ def test_assign_table(self):
4144
print(self.session.get_errors())
4245
raise ValueError("Failed to assign table") from e
4346

47+
@pytest.mark.integration
4448
def test_assign_resources(self):
4549
try:
4650
self.session.assign_resource(
@@ -64,6 +68,7 @@ def test_assign_resources(self):
6468
print(self.session.get_errors())
6569
raise ValueError("Failed to assign resources") from e
6670

71+
@pytest.mark.integration
6772
def test_assign_resource(self):
6873
try:
6974
self.session.assign_resource("client", resource="RSRC.CNSIM1", asynchronous=False)

tests/test_impl.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ def setup_class(cls):
2121
def teardown_class(cls):
2222
cls.session.close()
2323

24+
@pytest.mark.integration
2425
def test_driver(self):
2526
conn = self.conn
2627
assert conn.name == "server1"
2728

29+
@pytest.mark.integration
2830
def test_workspaces(self):
2931
conn = self.conn
3032
workspaces = conn.list_workspaces()
3133
assert type(workspaces) is list
3234

35+
@pytest.mark.integration
3336
def test_profiles(self):
3437
conn = self.conn
3538
profiles = conn.list_profiles()
@@ -39,6 +42,7 @@ def test_profiles(self):
3942
assert type(profiles["available"]) is list
4043
assert profiles["current"] == "default"
4144

45+
@pytest.mark.integration
4246
def test_methods(self):
4347
conn = self.conn
4448
methods = conn.list_methods(type="assign")
@@ -62,6 +66,7 @@ def test_methods(self):
6266
names = [x["name"] for x in methods]
6367
assert "meanDS" in names
6468

69+
@pytest.mark.integration
6570
def test_packages(self):
6671
conn = self.conn
6772
pkgs = conn.list_packages()
@@ -72,20 +77,23 @@ def test_packages(self):
7277
assert "resourcer" in names
7378
assert "dsBase" in names
7479

80+
@pytest.mark.integration
7581
def test_tables(self):
7682
conn = self.conn
7783
tables = conn.list_tables()
7884
assert type(tables) is list
7985
assert "CNSIM.CNSIM1" in tables
8086
assert conn.has_table("CNSIM.CNSIM1")
8187

88+
@pytest.mark.integration
8289
def test_resources(self):
8390
conn = self.conn
8491
resources = conn.list_resources()
8592
assert type(resources) is list
8693
assert "RSRC.CNSIM1" in resources
8794
assert conn.has_resource("RSRC.CNSIM1")
8895

96+
@pytest.mark.integration
8997
def test_assign_expr(self):
9098
conn = self.conn
9199
res = conn.assign_expr("x", "c(1, 2, 3)", asynchronous=False)
@@ -110,6 +118,7 @@ def test_assign_expr(self):
110118
assert type(symbols) is list
111119
assert len(symbols) == 0
112120

121+
@pytest.mark.integration
113122
def test_assign_table(self):
114123
conn = self.conn
115124
try:
@@ -138,6 +147,7 @@ def test_assign_table(self):
138147
print(e.get_error())
139148
raise ValueError("Assign table test failed") from e
140149

150+
@pytest.mark.integration
141151
def test_assign_resource(self):
142152
conn = self.conn
143153
try:
@@ -167,6 +177,7 @@ def test_assign_resource(self):
167177
print(e.get_error())
168178
raise ValueError("Assign resource test failed") from e
169179

180+
@pytest.mark.integration
170181
def test_aggregate(self):
171182
conn = self.conn
172183
try:
@@ -196,6 +207,7 @@ def test_aggregate(self):
196207
print(e.get_error())
197208
raise ValueError("Aggregate test failed") from e
198209

210+
@pytest.mark.integration
199211
def test_aggregate_function_not_allowed(self):
200212
conn = self.conn
201213
with pytest.raises(DSError) as exc_info:

0 commit comments

Comments
 (0)