|
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_hidden_attributes(): |
| 11 | + orig_config_val = config.get("enable_hidden_attributes") |
| 12 | + config["enable_hidden_attributes"] = True |
| 13 | + yield |
| 14 | + if orig_config_val is not None: |
| 15 | + config["enable_hidden_attributes"] = orig_config_val |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(scope="function") |
| 19 | +def disable_hidden_attributes(): |
| 20 | + orig_config_val = config.get("enable_hidden_attributes") |
| 21 | + config["enable_hidden_attributes"] = False |
| 22 | + yield |
| 23 | + if orig_config_val is not None: |
| 24 | + config["enable_hidden_attributes"] = orig_config_val |
6 | 25 |
|
7 | 26 |
|
8 | 27 | def test_schema_decorator(schema_any):
|
@@ -373,9 +392,35 @@ class Table_With_Underscores(dj.Manual):
|
373 | 392 | schema_any(Table_With_Underscores)
|
374 | 393 |
|
375 | 394 |
|
376 |
| -def test_hidden_attributes(schema_any): |
377 |
| - 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()) |
| 395 | +def test_hidden_attributes_default_value(): |
| 396 | + config_val = config.get("enable_hidden_attributes") |
| 397 | + assert config_val is not None and not config_val, \ |
| 398 | + "Default value for enable_hidden_attributes is not False" |
| 399 | + |
| 400 | + |
| 401 | +def test_hidden_attributes_enabled(enable_hidden_attributes, schema_any): |
| 402 | + orig_config_val = config.get("enable_hidden_attributes") |
| 403 | + config["enable_hidden_attributes"] = True |
| 404 | + |
| 405 | + msg = f"{Experiment().heading._attributes=}" |
| 406 | + assert any(a.name.endswith("_timestamp") for a in Experiment().heading._attributes.values()), msg |
| 407 | + assert any(a.name.startswith("_") for a in Experiment().heading._attributes.values()), msg |
| 408 | + assert any(a.is_hidden for a in Experiment().heading._attributes.values()), msg |
| 409 | + assert not any(a.is_hidden for a in Experiment().heading.attributes.values()), msg |
| 410 | + |
| 411 | + if orig_config_val is not None: |
| 412 | + config["enable_hidden_attributes"] = orig_config_val |
| 413 | + |
| 414 | + |
| 415 | +def test_hidden_attributes_disabled(disable_hidden_attributes, schema_any): |
| 416 | + orig_config_val = config.get("enable_hidden_attributes") |
| 417 | + config["enable_hidden_attributes"] = False |
| 418 | + |
| 419 | + msg = f"{Experiment().heading._attributes=}" |
| 420 | + assert not any(a.name.endswith("_timestamp") for a in Experiment().heading._attributes.values()), msg |
| 421 | + assert not any(a.name.startswith("_") for a in Experiment().heading._attributes.values()), msg |
| 422 | + assert not any(a.is_hidden for a in Experiment().heading._attributes.values()), msg |
| 423 | + assert not any(a.is_hidden for a in Experiment().heading.attributes.values()), msg |
| 424 | + |
| 425 | + if orig_config_val is not None: |
| 426 | + config["enable_hidden_attributes"] = orig_config_val |
0 commit comments