Skip to content

Commit 70f53d4

Browse files
Fix test compatibility with testcontainers
- Update settings tests to accept dynamic ports (testcontainers uses random ports instead of default 3306) - Fix test_top_restriction_with_keywords to use set comparison since dj.Top only guarantees which elements are selected, not their order - Bump version to 2.0.0a8 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d4560e6 commit 70f53d4

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

src/datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# version bump auto managed by Github Actions:
22
# label_prs.yaml(prep), release.yaml(bump), post_release.yaml(edit)
33
# manually set this version will be eventually overwritten by the above actions
4-
__version__ = "2.0.0a7"
4+
__version__ = "2.0.0a8"

tests/integration/test_relational_operand.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -561,30 +561,42 @@ def test_restrictions_by_top(self, schema_simp_pop):
561561
]
562562

563563
def test_top_restriction_with_keywords(self, schema_simp_pop):
564+
# dj.Top only guarantees which elements are selected, not their order
564565
select = SelectPK() & dj.Top(limit=9, order_by=["select desc"])
565566
key = KeyPK() & dj.Top(limit=9, order_by="key desc")
566-
assert select.fetch(as_dict=True) == [
567-
{"id": 2, "select": 8},
568-
{"id": 2, "select": 6},
569-
{"id": 1, "select": 4},
570-
{"id": 2, "select": 4},
571-
{"id": 1, "select": 3},
572-
{"id": 1, "select": 2},
573-
{"id": 2, "select": 2},
574-
{"id": 1, "select": 1},
575-
{"id": 0, "select": 0},
576-
]
577-
assert key.fetch(as_dict=True) == [
578-
{"id": 2, "key": 6},
579-
{"id": 2, "key": 5},
580-
{"id": 1, "key": 5},
581-
{"id": 0, "key": 4},
582-
{"id": 1, "key": 4},
583-
{"id": 2, "key": 4},
584-
{"id": 0, "key": 3},
585-
{"id": 1, "key": 3},
586-
{"id": 2, "key": 3},
587-
]
567+
# Convert to sets of tuples for order-independent comparison
568+
select_result = {tuple(sorted(d.items())) for d in select.fetch(as_dict=True)}
569+
select_expected = {
570+
tuple(sorted(d.items()))
571+
for d in [
572+
{"id": 2, "select": 8},
573+
{"id": 2, "select": 6},
574+
{"id": 1, "select": 4},
575+
{"id": 2, "select": 4},
576+
{"id": 1, "select": 3},
577+
{"id": 1, "select": 2},
578+
{"id": 2, "select": 2},
579+
{"id": 1, "select": 1},
580+
{"id": 0, "select": 0},
581+
]
582+
}
583+
assert select_result == select_expected
584+
key_result = {tuple(sorted(d.items())) for d in key.fetch(as_dict=True)}
585+
key_expected = {
586+
tuple(sorted(d.items()))
587+
for d in [
588+
{"id": 2, "key": 6},
589+
{"id": 2, "key": 5},
590+
{"id": 1, "key": 5},
591+
{"id": 0, "key": 4},
592+
{"id": 1, "key": 4},
593+
{"id": 2, "key": 4},
594+
{"id": 0, "key": 3},
595+
{"id": 1, "key": 3},
596+
{"id": 2, "key": 3},
597+
]
598+
}
599+
assert key_result == key_expected
588600

589601
def test_top_errors(self, schema_simp_pop):
590602
with pytest.raises(DataJointError) as err1:

tests/unit/test_settings.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ def test_attribute_access(self):
160160
# Host can be localhost or db (docker), just verify it's a string
161161
assert isinstance(dj.config.database.host, str)
162162
assert len(dj.config.database.host) > 0
163-
assert dj.config.database.port == 3306
163+
# Port may be 3306 (default) or a random port (testcontainers)
164+
assert isinstance(dj.config.database.port, int)
165+
assert 1 <= dj.config.database.port <= 65535
164166
# safemode may be modified by conftest fixtures
165167
assert isinstance(dj.config.safemode, bool)
166168

@@ -169,7 +171,9 @@ def test_dict_style_access(self):
169171
# Host can be localhost or db (docker), just verify it's a string
170172
assert isinstance(dj.config["database.host"], str)
171173
assert len(dj.config["database.host"]) > 0
172-
assert dj.config["database.port"] == 3306
174+
# Port may be 3306 (default) or a random port (testcontainers)
175+
assert isinstance(dj.config["database.port"], int)
176+
assert 1 <= dj.config["database.port"] <= 65535
173177
# safemode may be modified by conftest fixtures
174178
assert isinstance(dj.config["safemode"], bool)
175179

0 commit comments

Comments
 (0)