Skip to content

Commit aabdbe8

Browse files
authored
tests: add tests for session, service and graph export (#3017)
1 parent 71f0d4a commit aabdbe8

File tree

16 files changed

+932
-265
lines changed

16 files changed

+932
-265
lines changed

.github/workflows/test_deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ jobs:
774774
OLOS_ACCESS_TOKEN: ${{ secrets.OLOS_ACCESS_TOKEN }}
775775
RENKU_REQUESTS_TIMEOUT_SECONDS: 120
776776
run: pytest -m "integration and not service and not serial" -v --timeout=600 -n auto
777+
- name: Start Redis
778+
uses: supercharge/[email protected]
777779
- name: Test with pytest (serial)
778780
env:
779781
POETRY_VIRTUALENVS_CREATE: false
@@ -923,6 +925,8 @@ jobs:
923925
OLOS_ACCESS_TOKEN: ${{ secrets.OLOS_ACCESS_TOKEN }}
924926
RENKU_REQUESTS_TIMEOUT_SECONDS: 120
925927
run: pytest -m "integration and not serial" -v
928+
- name: Start Redis
929+
uses: supercharge/[email protected]
926930
- name: Test with pytest(serial)
927931
env:
928932
POETRY_VIRTUALENVS_CREATE: false

conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
GLOBAL_FIXTURE_LOCATIONS = [
4242
"tests.fixtures.common",
4343
"tests.fixtures.config",
44+
"tests.fixtures.domain_models",
4445
"tests.fixtures.repository",
4546
"tests.fixtures.runners",
47+
"tests.fixtures.session",
4648
"tests.fixtures.templates",
4749
]
4850

poetry.lock

Lines changed: 12 additions & 211 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ appdirs = "<=1.4.4,>=1.4.3"
5757
attrs = "<21.5.0,>=21.1.0"
5858
black = { version = "==22.3.0", optional = true }
5959
calamus = "<0.4,>=0.3.13"
60-
check-manifest = { version = ">=0.37,<0.49", optional = true }
6160
circus = { version = "==0.17.1", optional = true }
6261
click = ">=8.0,<8.1.3"
6362
click-option-group = "<0.6.0,>=0.5.2"
@@ -69,14 +68,12 @@ cwltool = "==3.1.20211107152837"
6968
deepdiff = "^5.8.0"
7069
deepmerge = "==1.0.1"
7170
docker = "<6,>=3.7.2"
72-
environ-config = ">=18.2.0,<22.2.0"
7371
fakeredis = { version = ">=1.4.1,<1.7.2", extras = ["lua"], optional = true }
7472
filelock = ">=3.3.0,<3.6.1"
7573
flake8 = { version = "<4.0,>=3.8", optional = true } #wait for https://github.com/flakehell/flakehell/pull/23 to be merged before bumping
7674
flakehell = { version = ">=0.9.0,<1.0.*", optional = true }
7775
flaky = { version = "==3.7.0", optional = true }
7876
flask = { version = "==2.1.1", optional = true }
79-
freezegun = { version = ">=0.3.12,<1.2.2", optional = true }
8077
gitpython = "==3.1.27"
8178
grandalf = "==0.7"
8279
gunicorn = { optional = true, version = "*" }
@@ -88,7 +85,6 @@ isort = { version = "<5.10.2,>=5.3.2", optional = true }
8885
jinja2 = { version = ">=2.11.3,<3.1.3" }
8986
marshmallow = { version = ">=3.13.0,<3.16.0", optional = true }
9087
mypy = {version = ">=0.942,<1.0", optional = true}
91-
ndg-httpsclient = "==0.5.1"
9288
networkx = "<2.7,>=2.6.0"
9389
numpy = ">=1.20.0,<1.22.0"
9490
packaging = "<22.0,>=21.3"
@@ -101,8 +97,6 @@ pluggy = "==1.0.0"
10197
poetry-dynamic-versioning = { version = "^0.14.0", optional = true }
10298
portalocker = ">=2.2.1,<2.5"
10399
psutil = ">=5.4.7,<5.9.1,"
104-
ptvsd = { version = "<4.4.0,>=4.3.0", optional = true }
105-
pyasn1 = "<=0.4.8,>=0.4.5"
106100
pydocstyle = { version = "<6.1.2,>=4.0.1", optional = true }
107101
pyjwt = ">=2.1.0,<2.4.0"
108102
pyld = "==2.0.3"
@@ -146,7 +140,6 @@ types-redis = { version=">=3.5.3,<4.1.0", optional = true }
146140
types-requests = { version = "<2.27.2,>=2.23.0", optional = true }
147141
types-tabulate = { version = "<0.8.10,>=0.7.7", optional = true }
148142
walrus = { version = ">=0.8.2,<0.10.0", optional = true }
149-
wcmatch = "<8.3,>=6.0.0"
150143
werkzeug = ">=1.0.0,<2.1.2"
151144
yagup = ">=0.1.1"
152145
yaspin = "==2.1.0"
@@ -328,6 +321,7 @@ markers = [
328321
"jobs: mark a test as a job test.",
329322
"migration: mark a test as a migration test.",
330323
"publish: mark tests that publish datasets to external providers.",
324+
"redis: mark tests that need a running redis",
331325
"serial: mark a test that can not be run in parallel",
332326
"service: mark a test as service test.",
333327
"shelled: mark a test as a shelled test.",

renku/command/graph.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050

5151
def export_graph_command():
5252
"""Return a command for exporting graph data."""
53-
return Command().command(_export_graph).with_database(write=False).require_migration()
53+
return Command().command(export_graph).with_database(write=False).require_migration()
5454

5555

5656
@inject.autoparams("client_dispatcher")
57-
def _export_graph(
57+
def export_graph(
5858
client_dispatcher: IClientDispatcher,
5959
format: str = "json-ld",
6060
revision_or_range: str = None,
@@ -75,9 +75,9 @@ def _export_graph(
7575
format = format.lower()
7676

7777
if revision_or_range:
78-
graph = _get_graph_for_revision(revision_or_range=revision_or_range)
78+
graph = get_graph_for_revision(revision_or_range=revision_or_range)
7979
else:
80-
graph = _get_graph_for_all_objects()
80+
graph = get_graph_for_all_objects()
8181

8282
# NOTE: rewrite ids for current environment
8383
host = get_host(client_dispatcher.current_client)
@@ -111,7 +111,7 @@ def update_nested_node_host(node: Dict, host: str) -> None:
111111

112112

113113
@inject.autoparams()
114-
def _get_graph_for_revision(
114+
def get_graph_for_revision(
115115
revision_or_range: str,
116116
database_gateway: IDatabaseGateway,
117117
project_gateway: IProjectGateway,
@@ -142,7 +142,7 @@ def _get_graph_for_revision(
142142

143143

144144
@inject.autoparams()
145-
def _get_graph_for_all_objects(
145+
def get_graph_for_all_objects(
146146
project_gateway: IProjectGateway,
147147
dataset_gateway: IDatasetGateway,
148148
activity_gateway: IActivityGateway,
@@ -223,6 +223,10 @@ def _convert_entities_to_graph(
223223
# NOTE: Since the database is read-only, it's OK to modify objects; they won't be written back
224224
entity.unfreeze()
225225
entity.project_id = project_id
226+
227+
if isinstance(entity, Activity):
228+
entity.association.plan.unfreeze()
229+
entity.association.plan.project_id = project_id
226230
schema = next(s for t, s in schemas.items() if isinstance(entity, t))
227231
graph.extend(schema(flattened=True).dump(entity))
228232

renku/domain_model/session.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,13 @@ def get_name(self) -> str:
4444
pass
4545

4646
@abstractmethod
47-
def build_image(self, image_descriptor: Path, image_name: str, config: Optional[Dict[str, Any]]) -> Optional[str]:
47+
def build_image(self, image_descriptor: Path, image_name: str, config: Optional[Dict[str, Any]]):
4848
"""Builds the container image.
4949
5050
Args:
5151
image_descriptor: Path to the container image descriptor file.
5252
image_name: Container image name.
5353
config: Path to the session provider specific configuration YAML.
54-
55-
Returns:
56-
str: a unique id for the created interactive session.
5754
"""
5855
pass
5956

renku/infrastructure/gateway/database_gateway.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ def commit(self) -> None:
142142

143143
def get_modified_objects_from_revision(self, revision_or_range: str) -> Generator[Persistent, None, None]:
144144
"""Get all database objects modified in a revision."""
145-
# TODO: use gateway once #renku-python/issues/2253 is done
146-
147145
client_dispatcher = inject.instance(IClientDispatcher)
148146
client = client_dispatcher.current_client
149147

run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ build_docs(){
5151
}
5252

5353
run_tests(){
54-
pytest -v -m "not integration and not publish" -o testpaths="tests renku conftest.py" --ignore=renku/version.py
54+
pytest -v -m "not integration and not publish and not redis" -o testpaths="tests renku conftest.py" --ignore=renku/version.py
5555
}
5656

5757
usage(){

tests/cli/test_graph.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929

3030
@pytest.mark.parametrize("revision", ["", "HEAD", "HEAD^", "HEAD^..HEAD"])
31-
@pytest.mark.parametrize("format", ["json-ld", "rdf", "nt"])
32-
def test_graph_export_validation(runner, client, directory_tree, run, revision, format):
31+
def test_graph_export_validation(runner, client, directory_tree, run, revision):
3332
"""Test graph validation when exporting."""
3433
assert 0 == runner.invoke(cli, ["dataset", "add", "-c", "my-data", str(directory_tree)]).exit_code
3534

@@ -38,15 +37,15 @@ def test_graph_export_validation(runner, client, directory_tree, run, revision,
3837
assert 0 == run(["run", "head", str(file1)], stdout="out1")
3938
assert 0 == run(["run", "tail", str(file2)], stdout="out2")
4039

41-
result = runner.invoke(cli, ["graph", "export", "--format", format, "--strict", "--revision", revision])
40+
result = runner.invoke(cli, ["graph", "export", "--format", "json-ld", "--strict", "--revision", revision])
4241

4342
assert 0 == result.exit_code, format_result_exception(result)
4443

4544
assert "https://localhost" in result.output
4645
assert "https://renkulab.io" not in result.output
4746

4847
with modified_environ(RENKU_DOMAIN="https://renkulab.io"):
49-
result = runner.invoke(cli, ["graph", "export", "--format", format, "--strict", "--revision", revision])
48+
result = runner.invoke(cli, ["graph", "export", "--format", "json-ld", "--strict", "--revision", revision])
5049

5150
assert 0 == result.exit_code, format_result_exception(result)
5251

@@ -59,16 +58,15 @@ def test_graph_export_validation(runner, client, directory_tree, run, revision,
5958

6059
@pytest.mark.serial
6160
@pytest.mark.shelled
62-
@pytest.mark.parametrize("format", ["json-ld", "nt", "rdf"])
63-
def test_graph_export_strict_run(runner, project, run_shell, format):
61+
def test_graph_export_strict_run(runner, project, run_shell):
6462
"""Test graph export output of run command."""
6563
# Run a shell command with pipe.
6664
assert run_shell('renku run --name run1 echo "my input string" > my_output_file')[1] is None
6765
assert run_shell("renku run --name run2 cp my_output_file my_output_file2")[1] is None
6866
assert run_shell("renku workflow compose my-composite-plan run1 run2")[1] is None
6967

7068
# Assert created output file.
71-
result = runner.invoke(cli, ["graph", "export", "--full", "--strict", "--format={}".format(format)])
69+
result = runner.invoke(cli, ["graph", "export", "--full", "--strict", "--format=json-ld"])
7270
assert 0 == result.exit_code, format_result_exception(result)
7371
assert "my_output_file" in result.output
7472
assert "my input string" in result.output
@@ -79,19 +77,18 @@ def test_graph_export_strict_run(runner, project, run_shell, format):
7977
assert run_shell("renku workflow remove run2")[1] is None
8078

8179
# Assert created output file.
82-
result = runner.invoke(cli, ["graph", "export", "--strict", "--format={}".format(format)])
80+
result = runner.invoke(cli, ["graph", "export", "--strict", "--format=json-ld"])
8381
assert 0 == result.exit_code, format_result_exception(result)
8482

8583

86-
@pytest.mark.parametrize("format", ["json-ld", "nt", "rdf"])
87-
def test_graph_export_strict_dataset(tmpdir, runner, project, client, format, subdirectory):
84+
def test_graph_export_strict_dataset(tmpdir, runner, project, client, subdirectory):
8885
"""Test output of graph export for dataset add."""
8986
result = runner.invoke(cli, ["dataset", "create", "my-dataset"])
9087
assert 0 == result.exit_code, format_result_exception(result)
9188
paths = []
9289
test_paths = []
9390
for i in range(3):
94-
new_file = tmpdir.join("file_{0}".format(i))
91+
new_file = tmpdir.join(f"file_{i}")
9592
new_file.write(str(i))
9693
paths.append(str(new_file))
9794
test_paths.append(os.path.relpath(str(new_file), str(project)))
@@ -100,14 +97,14 @@ def test_graph_export_strict_dataset(tmpdir, runner, project, client, format, su
10097
result = runner.invoke(cli, ["dataset", "add", "my-dataset"] + paths)
10198
assert 0 == result.exit_code, format_result_exception(result)
10299

103-
result = runner.invoke(cli, ["graph", "export", "--strict", f"--format={format}"])
100+
result = runner.invoke(cli, ["graph", "export", "--strict", "--format=json-ld"])
104101
assert 0 == result.exit_code, format_result_exception(result)
105102
assert all(p in result.output for p in test_paths), result.output
106103

107104
# check that only most recent dataset is exported
108105
assert 1 == result.output.count("http://schema.org/Dataset")
109106

110-
result = runner.invoke(cli, ["graph", "export", "--strict", f"--format={format}", "--full"])
107+
result = runner.invoke(cli, ["graph", "export", "--strict", "--format=json-ld", "--full"])
111108
assert 0 == result.exit_code, format_result_exception(result)
112109
assert all(p in result.output for p in test_paths), result.output
113110

tests/cli/test_integration_datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_dataset_import_real_doi_warnings(runner, project, sleep_after):
189189

190190
result = runner.invoke(cli, ["dataset", "ls"])
191191
assert 0 == result.exit_code, format_result_exception(result) + str(result.stderr_bytes)
192-
assert "pyndl_naive_discr_v0.6.0" in result.output
192+
assert "pyndl_naive_discr_v0.8.2" in result.output
193193

194194

195195
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)