|
3 | 3 | import datajoint as dj
|
4 | 4 | import inspect
|
5 | 5 | from datajoint.declare import declare
|
| 6 | +from datajoint.settings import config |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(scope="function") |
| 10 | +def enable_add_hidden_timestamp(): |
| 11 | + orig_config_val = config.get("add_hidden_timestamp") |
| 12 | + config["add_hidden_timestamp"] = True |
| 13 | + yield |
| 14 | + if orig_config_val is not None: |
| 15 | + config["add_hidden_timestamp"] = orig_config_val |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(scope="function") |
| 19 | +def disable_add_hidden_timestamp(): |
| 20 | + orig_config_val = config.get("add_hidden_timestamp") |
| 21 | + config["add_hidden_timestamp"] = False |
| 22 | + yield |
| 23 | + if orig_config_val is not None: |
| 24 | + config["add_hidden_timestamp"] = orig_config_val |
6 | 25 |
|
7 | 26 |
|
8 | 27 | def test_schema_decorator(schema_any):
|
@@ -373,9 +392,36 @@ class Table_With_Underscores(dj.Manual):
|
373 | 392 | schema_any(Table_With_Underscores)
|
374 | 393 |
|
375 | 394 |
|
376 |
| -def test_hidden_attributes(schema_any): |
| 395 | +def test_add_hidden_timestamp_default_value(): |
| 396 | + config_val = config.get("add_hidden_timestamp") |
377 | 397 | assert (
|
378 |
| - list(Experiment().heading._attributes.keys())[-1].split("_")[2] == "timestamp" |
379 |
| - ) |
380 |
| - assert any(a.is_hidden for a in Experiment().heading._attributes.values()) |
381 |
| - assert not any(a.is_hidden for a in Experiment().heading.attributes.values()) |
| 398 | + config_val is not None and not config_val |
| 399 | + ), "Default value for add_hidden_timestamp is not False" |
| 400 | + |
| 401 | + |
| 402 | +def test_add_hidden_timestamp_enabled(enable_add_hidden_timestamp, schema_any): |
| 403 | + assert config["add_hidden_timestamp"], "add_hidden_timestamp is not enabled" |
| 404 | + msg = f"{Experiment().heading._attributes=}" |
| 405 | + assert any( |
| 406 | + a.name.endswith("_timestamp") for a in Experiment().heading._attributes.values() |
| 407 | + ), msg |
| 408 | + assert any( |
| 409 | + a.name.startswith("_") for a in Experiment().heading._attributes.values() |
| 410 | + ), msg |
| 411 | + assert any(a.is_hidden for a in Experiment().heading._attributes.values()), msg |
| 412 | + assert not any(a.is_hidden for a in Experiment().heading.attributes.values()), msg |
| 413 | + |
| 414 | + |
| 415 | +def test_add_hidden_timestamp_disabled(disable_add_hidden_timestamp, schema_any): |
| 416 | + assert not config[ |
| 417 | + "add_hidden_timestamp" |
| 418 | + ], "expected add_hidden_timestamp to be False" |
| 419 | + msg = f"{Experiment().heading._attributes=}" |
| 420 | + assert not any( |
| 421 | + a.name.endswith("_timestamp") for a in Experiment().heading._attributes.values() |
| 422 | + ), msg |
| 423 | + assert not any( |
| 424 | + a.name.startswith("_") for a in Experiment().heading._attributes.values() |
| 425 | + ), msg |
| 426 | + assert not any(a.is_hidden for a in Experiment().heading._attributes.values()), msg |
| 427 | + assert not any(a.is_hidden for a in Experiment().heading.attributes.values()), msg |
0 commit comments