From 13bc5329947f069026dcd6790f3c9ac783efb6dc Mon Sep 17 00:00:00 2001 From: A-Baji Date: Tue, 28 Nov 2023 12:36:04 -0600 Subject: [PATCH 1/3] test: :white_check_mark: convert test_aggr_regressions to pytest --- tests/schema_uuid.py | 50 +++++++++++++++++++ {tests_old => tests}/test_aggr_regressions.py | 28 ++++------- 2 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 tests/schema_uuid.py rename {tests_old => tests}/test_aggr_regressions.py (75%) diff --git a/tests/schema_uuid.py b/tests/schema_uuid.py new file mode 100644 index 000000000..bcf410c65 --- /dev/null +++ b/tests/schema_uuid.py @@ -0,0 +1,50 @@ +import uuid +import datajoint as dj +from . import PREFIX, CONN_INFO_ROOT + +schema = dj.Schema(PREFIX + "_test1", connection=dj.conn(**CONN_INFO_ROOT)) + +top_level_namespace_id = uuid.UUID("00000000-0000-0000-0000-000000000000") + + +@schema +class Basic(dj.Manual): + definition = """ + item : uuid + --- + number : int + """ + + +@schema +class Topic(dj.Manual): + definition = """ + # A topic for items + topic_id : uuid # internal identification of a topic, reflects topic name + --- + topic : varchar(8000) # full topic name used to generate the topic id + """ + + def add(self, topic): + """add a new topic with a its UUID""" + self.insert1( + dict(topic_id=uuid.uuid5(top_level_namespace_id, topic), topic=topic) + ) + + +@schema +class Item(dj.Computed): + definition = """ + item_id : uuid # internal identification of + --- + -> Topic + word : varchar(8000) + """ + + key_source = Topic # test key source that is not instantiated + + def make(self, key): + for word in ("Habenula", "Hippocampus", "Hypothalamus", "Hypophysis"): + self.insert1( + dict(key, word=word, item_id=uuid.uuid5(key["topic_id"], word)) + ) diff --git a/tests_old/test_aggr_regressions.py b/tests/test_aggr_regressions.py similarity index 75% rename from tests_old/test_aggr_regressions.py rename to tests/test_aggr_regressions.py index 18ed0ba84..7d6c15da7 100644 --- a/tests_old/test_aggr_regressions.py +++ b/tests/test_aggr_regressions.py @@ -1,20 +1,15 @@ -""" -Regression tests for issues 386, 449, 484, and 558 — all related to processing complex aggregations and projections. -""" - import itertools -from nose.tools import assert_equal import datajoint as dj -from . import PREFIX, CONN_INFO +from . import PREFIX, CONN_INFO_ROOT import uuid from .schema_uuid import Topic, Item, top_level_namespace_id -schema = dj.Schema(PREFIX + "_aggr_regress", connection=dj.conn(**CONN_INFO)) +schema = dj.Schema(PREFIX + "_aggr_regress", connection=dj.conn(**CONN_INFO_ROOT)) # --------------- ISSUE 386 ------------------- # Issue 386 resulted from the loss of aggregated attributes when the aggregation was used as the restrictor -# Q & (R.aggr(S, n='count(*)') & 'n=2') -# Error: Unknown column 'n' in HAVING +# Q & (R.aggr(S, n='count(*)') & 'n=2') +# Error: Unknown column 'n' in HAVING @schema @@ -69,8 +64,8 @@ def test_issue484(): # --------------- ISSUE 558 ------------------ -# Issue 558 resulted from the fact that DataJoint saves subqueries and often combines a restriction followed -# by a projection into a single SELECT statement, which in several unusual cases produces unexpected results. +# Issue 558 resulted from the fact that DataJoint saves subqueries and often combines a restriction followed +# by a projection into a single SELECT statement, which in several unusual cases produces unexpected results. @schema @@ -100,19 +95,16 @@ class X(dj.Lookup): def test_issue558_part1(): q = (A - B).proj(id2="3") - assert_equal(len(A - B), len(q)) + assert len(A - B) == len(q) def test_issue558_part2(): d = dict(id=3, id2=5) - assert_equal(len(X & d), len((X & d).proj(id2="3"))) + assert len(X & d) == len((X & d).proj(id2="3")) def test_left_join_len(): - Topic().add("jeff") Item.populate() - Topic().add("jeff2") - Topic().add("jeff3") q = Topic.join( Item - dict(topic_id=uuid.uuid5(top_level_namespace_id, "jeff")), left=True ) @@ -122,8 +114,8 @@ def test_left_join_len(): def test_union_join(): # https://github.com/datajoint/datajoint-python/issues/930 - A.insert(zip([100, 200, 300, 400, 500, 600])) - B.insert([(100, 11), (200, 22), (300, 33), (400, 44)]) + A.insert(zip([100, 200, 300, 400, 500, 600]), skip_duplicates=True) + B.insert([(100, 11), (200, 22), (300, 33), (400, 44)], skip_duplicates=True) q1 = B & "id < 300" q2 = B & "id > 300" From bea08a341572186f91a435c04afedae54283c35d Mon Sep 17 00:00:00 2001 From: A-Baji Date: Tue, 28 Nov 2023 13:01:40 -0600 Subject: [PATCH 2/3] build: :arrow_up: update nginx version --- LNX-docker-compose.yml | 2 +- local-docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LNX-docker-compose.yml b/LNX-docker-compose.yml index 9c0a95b78..a458a426a 100644 --- a/LNX-docker-compose.yml +++ b/LNX-docker-compose.yml @@ -44,7 +44,7 @@ services: interval: 15s fakeservices.datajoint.io: <<: *net - image: datajoint/nginx:v0.2.6 + image: datajoint/nginx:v0.2.7 environment: - ADD_db_TYPE=DATABASE - ADD_db_ENDPOINT=db:3306 diff --git a/local-docker-compose.yml b/local-docker-compose.yml index 62b52ad66..567235a74 100644 --- a/local-docker-compose.yml +++ b/local-docker-compose.yml @@ -46,7 +46,7 @@ services: interval: 15s fakeservices.datajoint.io: <<: *net - image: datajoint/nginx:v0.2.6 + image: datajoint/nginx:v0.2.7 environment: - ADD_db_TYPE=DATABASE - ADD_db_ENDPOINT=db:3306 From bcf814649b744d27d747ff93d8f1d3cfa8293101 Mon Sep 17 00:00:00 2001 From: A-Baji Date: Tue, 28 Nov 2023 13:06:04 -0600 Subject: [PATCH 3/3] refactor: :bulb: comments --- tests/test_aggr_regressions.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_aggr_regressions.py b/tests/test_aggr_regressions.py index 7d6c15da7..672d62bd2 100644 --- a/tests/test_aggr_regressions.py +++ b/tests/test_aggr_regressions.py @@ -1,3 +1,7 @@ +""" +Regression tests for issues 386, 449, 484, and 558 — all related to processing complex aggregations and projections. +""" + import itertools import datajoint as dj from . import PREFIX, CONN_INFO_ROOT @@ -8,8 +12,8 @@ # --------------- ISSUE 386 ------------------- # Issue 386 resulted from the loss of aggregated attributes when the aggregation was used as the restrictor -# Q & (R.aggr(S, n='count(*)') & 'n=2') -# Error: Unknown column 'n' in HAVING +# Q & (R.aggr(S, n='count(*)') & 'n=2') +# Error: Unknown column 'n' in HAVING @schema @@ -64,8 +68,8 @@ def test_issue484(): # --------------- ISSUE 558 ------------------ -# Issue 558 resulted from the fact that DataJoint saves subqueries and often combines a restriction followed -# by a projection into a single SELECT statement, which in several unusual cases produces unexpected results. +# Issue 558 resulted from the fact that DataJoint saves subqueries and often combines a restriction followed +# by a projection into a single SELECT statement, which in several unusual cases produces unexpected results. @schema