From c4cdf615c5516f44d96c9c6806d956ad38104a7e Mon Sep 17 00:00:00 2001 From: Ethan Ho <53266718+ethho@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:15:13 +0000 Subject: [PATCH 1/3] Linting --- tests/test_autopopulate.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_autopopulate.py b/tests/test_autopopulate.py index d1f0726e..ebe6f4cd 100644 --- a/tests/test_autopopulate.py +++ b/tests/test_autopopulate.py @@ -10,7 +10,8 @@ def test_populate(trial, subject, experiment, ephys, channel): assert subject, "root tables are empty" assert not experiment, "table already filled?" experiment.populate() - assert len(experiment) == len(subject) * experiment.fake_experiments_per_subject + assert len(experiment) == len(subject) * \ + experiment.fake_experiments_per_subject # test restricted populate assert not trial, "table already filled?" @@ -62,7 +63,8 @@ def test_populate_exclude_error_and_ignore_jobs(schema_any, subject, experiment) schema_any.jobs.error(experiment.table_name, key, "") experiment.populate(reserve_jobs=True) - assert len(experiment.key_source & experiment) == len(experiment.key_source) - 2 + assert len(experiment.key_source & experiment) == len( + experiment.key_source) - 2 def test_allow_direct_insert(subject, experiment): @@ -78,7 +80,8 @@ def test_multi_processing(subject, experiment, processes): assert subject, "root tables are empty" assert not experiment, "table already filled?" experiment.populate(processes=None) - assert len(experiment) == len(subject) * experiment.fake_experiments_per_subject + assert len(experiment) == len(subject) * \ + experiment.fake_experiments_per_subject def test_allow_insert(subject, experiment): From 1ca975e8e8ff8a3d4c85c0b37aedbb25b3e0fba6 Mon Sep 17 00:00:00 2001 From: Ethan Ho <53266718+ethho@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:16:18 +0000 Subject: [PATCH 2/3] Use schema_any fixture instead of importing into module namespace --- tests/test_autopopulate.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/test_autopopulate.py b/tests/test_autopopulate.py index ebe6f4cd..d0e9dad7 100644 --- a/tests/test_autopopulate.py +++ b/tests/test_autopopulate.py @@ -1,11 +1,9 @@ import pytest from datajoint import DataJointError import datajoint as dj -import pymysql -from . import schema -def test_populate(trial, subject, experiment, ephys, channel): +def test_populate(schema_any, trial, subject, experiment, ephys, channel): # test simple populate assert subject, "root tables are empty" assert not experiment, "table already filled?" @@ -32,7 +30,7 @@ def test_populate(trial, subject, experiment, ephys, channel): assert channel -def test_populate_with_success_count(subject, experiment, trial): +def test_populate_with_success_count(schema_any, subject, experiment, trial): # test simple populate assert subject, "root tables are empty" assert not experiment, "table already filled?" @@ -67,7 +65,7 @@ def test_populate_exclude_error_and_ignore_jobs(schema_any, subject, experiment) experiment.key_source) - 2 -def test_allow_direct_insert(subject, experiment): +def test_allow_direct_insert(schema_any, subject, experiment): assert subject, "root tables are empty" key = subject.fetch("KEY", limit=1)[0] key["experiment_id"] = 1000 @@ -76,7 +74,7 @@ def test_allow_direct_insert(subject, experiment): @pytest.mark.parametrize("processes", [None, 2]) -def test_multi_processing(subject, experiment, processes): +def test_multi_processing(schema_any, subject, experiment, processes): assert subject, "root tables are empty" assert not experiment, "table already filled?" experiment.populate(processes=None) @@ -84,7 +82,7 @@ def test_multi_processing(subject, experiment, processes): experiment.fake_experiments_per_subject -def test_allow_insert(subject, experiment): +def test_allow_insert(schema_any, subject, experiment): assert subject, "root tables are empty" key = subject.fetch("KEY")[0] key["experiment_id"] = 1001 From 78d47210333c7d1da1f0a9b63e66f0e52065f0be Mon Sep 17 00:00:00 2001 From: Ethan Ho <53266718+ethho@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:47:44 -0500 Subject: [PATCH 3/3] Add test case to schema_simple for three part make function --- tests/conftest.py | 1 + tests/schema_simple.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 65d68268..86135ecd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -336,6 +336,7 @@ def schema_simp(connection_test, prefix): schema(schema_simple.B) schema(schema_simple.L) schema(schema_simple.D) + schema(schema_simple.N) schema(schema_simple.E) schema(schema_simple.F) schema(schema_simple.F) diff --git a/tests/schema_simple.py b/tests/schema_simple.py index 9e3113c9..c563abea 100644 --- a/tests/schema_simple.py +++ b/tests/schema_simple.py @@ -92,7 +92,33 @@ def _make_tuples(self, key): # make reference to a random tuple from L random.seed(str(key)) lookup = list(L().fetch("KEY")) - self.insert(dict(key, id_d=i, **random.choice(lookup)) for i in range(4)) + self.insert(dict(key, id_d=i, **random.choice(lookup)) + for i in range(4)) + + +class N(dj.Computed): + definition = """ + # test for three part make function + -> A + id_d :int + --- + -> L + """ + + def make_fetch(self, key): + # make reference to a random tuple from L + lookup = list(L().fetch("KEY")) + inputs = key, lookup + return inputs + + def make_compute(self, inputs): + key, lookup = inputs + random.seed(str(key)) + values = [dict(key, id_d=i, **random.choice(lookup)) for i in range(4)] + return values + + def make_insert(self, values): + self.insert(values) class E(dj.Computed):