|
1 | 1 | import pytest |
2 | 2 | import re |
3 | 3 | import datajoint as dj |
4 | | -from . import schema as schema_any_module, schema_alter as schema_alter_module, PREFIX |
5 | | -from .schema_alter import Parent, Experiment |
| 4 | +from . import schema as schema_any_module, PREFIX |
6 | 5 |
|
| 6 | + |
| 7 | +class Experiment(dj.Imported): |
| 8 | + original_definition = """ # information about experiments |
| 9 | + -> Subject |
| 10 | + experiment_id :smallint # experiment number for this subject |
| 11 | + --- |
| 12 | + experiment_date :date # date when experiment was started |
| 13 | + -> [nullable] User |
| 14 | + data_path="" :varchar(255) # file path to recorded data |
| 15 | + notes="" :varchar(2048) # e.g. purpose of experiment |
| 16 | + entry_time=CURRENT_TIMESTAMP :timestamp # automatic timestamp |
| 17 | + """ |
| 18 | + |
| 19 | + definition1 = """ # Experiment |
| 20 | + -> Subject |
| 21 | + experiment_id :smallint # experiment number for this subject |
| 22 | + --- |
| 23 | + data_path : int # some number |
| 24 | + extra=null : longblob # just testing |
| 25 | + -> [nullable] User |
| 26 | + subject_notes=null :varchar(2048) # {notes} e.g. purpose of experiment |
| 27 | + entry_time=CURRENT_TIMESTAMP :timestamp # automatic timestamp |
| 28 | + """ |
| 29 | + |
| 30 | + |
| 31 | +class Parent(dj.Manual): |
| 32 | + definition = """ |
| 33 | + parent_id: int |
| 34 | + """ |
| 35 | + |
| 36 | + class Child(dj.Part): |
| 37 | + definition = """ |
| 38 | + -> Parent |
| 39 | + """ |
| 40 | + definition_new = """ |
| 41 | + -> master |
| 42 | + --- |
| 43 | + child_id=null: int |
| 44 | + """ |
| 45 | + |
| 46 | + class Grandchild(dj.Part): |
| 47 | + definition = """ |
| 48 | + -> master.Child |
| 49 | + """ |
| 50 | + definition_new = """ |
| 51 | + -> master.Child |
| 52 | + --- |
| 53 | + grandchild_id=null: int |
| 54 | + """ |
| 55 | + |
| 56 | + |
| 57 | +LOCALS_ALTER = {"Experiment": Experiment, "Parent": Parent} |
7 | 58 | COMBINED_CONTEXT = { |
8 | 59 | **schema_any_module.LOCALS_ANY, |
9 | | - **schema_alter_module.LOCALS_ALTER, |
| 60 | + **LOCALS_ALTER, |
10 | 61 | } |
11 | 62 |
|
12 | 63 |
|
13 | 64 | @pytest.fixture |
14 | | -def schema_alter(connection_test): |
15 | | - schema_any = dj.Schema( |
16 | | - PREFIX + "_alter", |
17 | | - context=schema_any_module.LOCALS_ANY, |
18 | | - connection=connection_test, |
19 | | - ) |
20 | | - schema_any(schema_any_module.TTest) |
21 | | - schema_any(schema_any_module.TTest2) |
22 | | - schema_any(schema_any_module.TTest3) |
23 | | - schema_any(schema_any_module.NullableNumbers) |
24 | | - schema_any(schema_any_module.TTestExtra) |
25 | | - schema_any(schema_any_module.TTestNoExtra) |
26 | | - schema_any(schema_any_module.Auto) |
27 | | - schema_any(schema_any_module.User) |
28 | | - schema_any(schema_any_module.Subject) |
29 | | - schema_any(schema_any_module.Language) |
30 | | - schema_any(schema_any_module.Experiment) |
31 | | - schema_any(schema_any_module.Trial) |
32 | | - schema_any(schema_any_module.Ephys) |
33 | | - schema_any(schema_any_module.Image) |
34 | | - schema_any(schema_any_module.UberTrash) |
35 | | - schema_any(schema_any_module.UnterTrash) |
36 | | - schema_any(schema_any_module.SimpleSource) |
37 | | - schema_any(schema_any_module.SigIntTable) |
38 | | - schema_any(schema_any_module.SigTermTable) |
39 | | - schema_any(schema_any_module.DjExceptionName) |
40 | | - schema_any(schema_any_module.ErrorClass) |
41 | | - schema_any(schema_any_module.DecimalPrimaryKey) |
42 | | - schema_any(schema_any_module.IndexRich) |
43 | | - schema_any(schema_any_module.ThingA) |
44 | | - schema_any(schema_any_module.ThingB) |
45 | | - schema_any(schema_any_module.ThingC) |
46 | | - schema_any(schema_any_module.Parent) |
47 | | - schema_any(schema_any_module.Child) |
48 | | - schema_any(schema_any_module.ComplexParent) |
49 | | - schema_any(schema_any_module.ComplexChild) |
50 | | - schema_any(schema_any_module.SubjectA) |
51 | | - schema_any(schema_any_module.SessionA) |
52 | | - schema_any(schema_any_module.SessionStatusA) |
53 | | - schema_any(schema_any_module.SessionDateA) |
54 | | - schema_any(schema_any_module.Stimulus) |
55 | | - schema_any(schema_any_module.Longblob) |
56 | | - |
57 | | - # Add nodes from schema_alter_module |
58 | | - schema_any(Experiment, context=schema_alter_module.LOCALS_ALTER) |
59 | | - schema_any(Parent, context=schema_alter_module.LOCALS_ALTER) |
60 | | - |
| 65 | +def schema_alter(connection_test, schema_any): |
| 66 | + # Overwrite Experiment and Parent nodes |
| 67 | + schema_any(Experiment, context=LOCALS_ALTER) |
| 68 | + schema_any(Parent, context=LOCALS_ALTER) |
61 | 69 | yield schema_any |
62 | 70 | schema_any.drop() |
63 | 71 |
|
|
0 commit comments