CifQL 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cifql-0.2.0 → cifql-0.2.1}/CifQL.egg-info/PKG-INFO +1 -1
- {cifql-0.2.0 → cifql-0.2.1}/PKG-INFO +1 -1
- {cifql-0.2.0 → cifql-0.2.1}/cifql/__init__.py +1 -1
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_config.py +12 -8
- {cifql-0.2.0 → cifql-0.2.1}/cifql/loader.py +22 -1
- {cifql-0.2.0 → cifql-0.2.1}/cifql/mcp_server/query.py +74 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_cif2db.py +13 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_config.py +22 -7
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_loader.py +58 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_mcp_query.py +88 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_orm.py +13 -4
- {cifql-0.2.0 → cifql-0.2.1}/CifQL.egg-info/SOURCES.txt +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/CifQL.egg-info/dependency_links.txt +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/CifQL.egg-info/entry_points.txt +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/CifQL.egg-info/requires.txt +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/CifQL.egg-info/top_level.txt +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/LICENSE +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/README.md +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/__main__.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_argparse.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_checks.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_cli.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_errors.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_logging.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_orm.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/_utils.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/cif2db.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/completion.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dic2json.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dic2orm.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dic_usage.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dics/__init__.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dics/mmcif_pdbx/__init__.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dics/mmcif_pdbx/v5_417/__init__.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dics/mmcif_pdbx/v5_417/dic_descriptions.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dics/mmcif_pdbx/v5_417/ingest.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/dics/mmcif_pdbx/v5_417/models.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/mcp_server/__init__.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/mcp_server/server.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/cifql/text_index.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/pyproject.toml +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/setup.cfg +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_argparse.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_cli.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_completion.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_dic2json.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_dic2orm.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_dic_usage.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_errors.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_logging.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_mcp_server.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_text_index.py +0 -0
- {cifql-0.2.0 → cifql-0.2.1}/tests/test_utils.py +0 -0
|
@@ -32,8 +32,8 @@ logger = logging.getLogger(__name__)
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
def _read_yaml(path, source):
|
|
35
|
-
"""The mapping in the YAML file `path
|
|
36
|
-
|
|
35
|
+
"""The mapping in the YAML file `path`. `source` says where the path came
|
|
36
|
+
from."""
|
|
37
37
|
try:
|
|
38
38
|
with open(path, encoding="utf8") as yfh:
|
|
39
39
|
config = yaml.safe_load(yfh)
|
|
@@ -43,12 +43,19 @@ def _read_yaml(path, source):
|
|
|
43
43
|
raise ConfigError(
|
|
44
44
|
f"Configuration file '{path}' ({source}) can not be used: {reason}"
|
|
45
45
|
) from exc
|
|
46
|
-
|
|
46
|
+
# An empty file is never what someone meant, the next source would be
|
|
47
|
+
# used without them knowing.
|
|
48
|
+
if config is None:
|
|
49
|
+
raise ConfigError(
|
|
50
|
+
f"Configuration file '{path}' ({source}) can not be used: it is "
|
|
51
|
+
+ "empty"
|
|
52
|
+
)
|
|
53
|
+
if not isinstance(config, dict):
|
|
47
54
|
raise ConfigError(
|
|
48
55
|
f"Configuration file '{path}' ({source}) can not be used: not a "
|
|
49
56
|
+ "mapping of settings"
|
|
50
57
|
)
|
|
51
|
-
databases =
|
|
58
|
+
databases = config.get("DATABASES", {})
|
|
52
59
|
if not isinstance(databases, dict) or not all(
|
|
53
60
|
isinstance(settings, dict) for settings in databases.values()
|
|
54
61
|
):
|
|
@@ -86,13 +93,10 @@ def get_config(path_to_yaml=None):
|
|
|
86
93
|
(os.environ.get("CIFQL_CONFIG_YAML", None), "$CIFQL_CONFIG_YAML"),
|
|
87
94
|
(conf_file, "default path"),
|
|
88
95
|
]
|
|
89
|
-
config = None
|
|
90
96
|
for src in sources:
|
|
91
97
|
if src[0] is not None:
|
|
92
|
-
|
|
93
|
-
if config is not None:
|
|
98
|
+
defaults.update(_read_yaml(*src))
|
|
94
99
|
logger.debug("Reading config from %s (%s)", src[1], src[0])
|
|
95
|
-
defaults.update(config)
|
|
96
100
|
return defaults
|
|
97
101
|
|
|
98
102
|
logger.warning("No config found/ specified, running with defaults.")
|
|
@@ -72,6 +72,7 @@ from pathlib import Path
|
|
|
72
72
|
import importlib.machinery
|
|
73
73
|
import importlib.util
|
|
74
74
|
import os
|
|
75
|
+
import traceback
|
|
75
76
|
|
|
76
77
|
from ._errors import LoaderFileError
|
|
77
78
|
|
|
@@ -102,6 +103,19 @@ class Loader:
|
|
|
102
103
|
it as it is."""
|
|
103
104
|
|
|
104
105
|
|
|
106
|
+
def _traceback_in(exc, plugin):
|
|
107
|
+
"""The traceback of `exc` from the first line of the file `plugin` on,
|
|
108
|
+
Python's import machinery before it says nothing to its author."""
|
|
109
|
+
frames = exc.__traceback__
|
|
110
|
+
while (
|
|
111
|
+
frames is not None
|
|
112
|
+
and frames.tb_frame.f_code.co_filename != os.fspath(plugin)
|
|
113
|
+
):
|
|
114
|
+
frames = frames.tb_next
|
|
115
|
+
|
|
116
|
+
return "".join(traceback.format_exception(type(exc), exc, frames)).rstrip()
|
|
117
|
+
|
|
118
|
+
|
|
105
119
|
def load_loader(plugin):
|
|
106
120
|
"""The one Loader subclass defined in the Python file `plugin`."""
|
|
107
121
|
name = f"cifql_loader_{Path(plugin).stem}"
|
|
@@ -110,7 +124,14 @@ def load_loader(plugin):
|
|
|
110
124
|
name, importlib.machinery.SourceFileLoader(name, os.fspath(plugin))
|
|
111
125
|
)
|
|
112
126
|
module = importlib.util.module_from_spec(spec)
|
|
113
|
-
|
|
127
|
+
try:
|
|
128
|
+
spec.loader.exec_module(module)
|
|
129
|
+
# Whatever the loader's own code raises, a syntax error included.
|
|
130
|
+
except Exception as exc: # pylint: disable=broad-exception-caught
|
|
131
|
+
raise LoaderFileError(
|
|
132
|
+
f"'{plugin}' can not be loaded: {type(exc).__name__}: {exc}\n"
|
|
133
|
+
+ _traceback_in(exc, plugin)
|
|
134
|
+
) from exc
|
|
114
135
|
found = sorted(
|
|
115
136
|
(
|
|
116
137
|
obj
|
|
@@ -536,6 +536,50 @@ class Explorer: # pylint: disable=too-many-instance-attributes
|
|
|
536
536
|
|
|
537
537
|
return None
|
|
538
538
|
|
|
539
|
+
@staticmethod
|
|
540
|
+
def _link_spelt(model, part):
|
|
541
|
+
"""The link of `model` that `part` names when underscores are left
|
|
542
|
+
out: a category as the dictionary writes it, 'entity_src_gen', is
|
|
543
|
+
the link 'entitysrcgen'. Items are not compared this way."""
|
|
544
|
+
wanted = part.replace("_", "")
|
|
545
|
+
for fld in model._meta.get_fields():
|
|
546
|
+
if fld.is_relation and fld.name.replace("_", "") == wanted:
|
|
547
|
+
return fld
|
|
548
|
+
|
|
549
|
+
return None
|
|
550
|
+
|
|
551
|
+
def _leads_on(self, model, fld, part):
|
|
552
|
+
"""Whether the link `fld` of `model` may show the way to `part`: to
|
|
553
|
+
another category, and nothing hidden on either side."""
|
|
554
|
+
target = fld.related_model
|
|
555
|
+
return (
|
|
556
|
+
fld.is_relation
|
|
557
|
+
and target is not model
|
|
558
|
+
and hasattr(target, "cif_name")
|
|
559
|
+
and not (model is self.block and fld.name in INTERNAL)
|
|
560
|
+
and not (target is self.block and part in INTERNAL)
|
|
561
|
+
)
|
|
562
|
+
|
|
563
|
+
def _ways_to(self, model, part):
|
|
564
|
+
"""The links of `model` to categories that have `part`, as (link,
|
|
565
|
+
category, the name there): a query that missed a category by one
|
|
566
|
+
link is told the way. Links back to `model` are no way further."""
|
|
567
|
+
ways = []
|
|
568
|
+
for fld in model._meta.get_fields():
|
|
569
|
+
if not self._leads_on(model, fld, part):
|
|
570
|
+
continue
|
|
571
|
+
target = fld.related_model
|
|
572
|
+
try:
|
|
573
|
+
found = target._meta.get_field(part)
|
|
574
|
+
except FieldDoesNotExist:
|
|
575
|
+
found = self._link_spelt(target, part)
|
|
576
|
+
if found is not None and not (
|
|
577
|
+
found.is_relation and found.related_model is model
|
|
578
|
+
):
|
|
579
|
+
ways.append((fld.name, target, found.name))
|
|
580
|
+
|
|
581
|
+
return ways
|
|
582
|
+
|
|
539
583
|
def _resolve(self, model, lookup):
|
|
540
584
|
"""Check a Django lookup against the ORM. Returns the field it ends
|
|
541
585
|
at and its comparison."""
|
|
@@ -563,6 +607,36 @@ class Explorer: # pylint: disable=too-many-instance-attributes
|
|
|
563
607
|
except FieldDoesNotExist:
|
|
564
608
|
if field is not None and last and part in field.get_lookups():
|
|
565
609
|
return field, part
|
|
610
|
+
missed = f"'{lookup}': '{current.cif_name}' has no '{part}'"
|
|
611
|
+
spelt = self._link_spelt(current, part)
|
|
612
|
+
if spelt is not None:
|
|
613
|
+
raise QueryError(
|
|
614
|
+
f"{missed}, it is called '{spelt.name}' here: use '"
|
|
615
|
+
+ "__".join(
|
|
616
|
+
parts[:pos] + [spelt.name] + parts[pos + 1 :]
|
|
617
|
+
)
|
|
618
|
+
+ "'"
|
|
619
|
+
) from None
|
|
620
|
+
ways = self._ways_to(current, part)
|
|
621
|
+
# A few ways are named, more get the list.
|
|
622
|
+
if 0 < len(ways) <= 3:
|
|
623
|
+
raise QueryError(
|
|
624
|
+
f"{missed}, it hangs off "
|
|
625
|
+
+ " or ".join(
|
|
626
|
+
f"'{cat.cif_name}'"
|
|
627
|
+
+ (f" as '{there}'" if there != part else "")
|
|
628
|
+
for _, cat, there in ways
|
|
629
|
+
)
|
|
630
|
+
+ ": use "
|
|
631
|
+
+ " or ".join(
|
|
632
|
+
"'"
|
|
633
|
+
+ "__".join(
|
|
634
|
+
parts[:pos] + [link, there] + parts[pos + 1 :]
|
|
635
|
+
)
|
|
636
|
+
+ "'"
|
|
637
|
+
for link, _, there in ways
|
|
638
|
+
)
|
|
639
|
+
) from None
|
|
566
640
|
names = sorted(
|
|
567
641
|
fld.name
|
|
568
642
|
for fld in current._meta.get_fields()
|
|
@@ -2001,6 +2001,19 @@ def test_main_reads_a_file_reached_twice_only_once(tmp_path):
|
|
|
2001
2001
|
assert parse.call_count == 1
|
|
2002
2002
|
|
|
2003
2003
|
|
|
2004
|
+
def test_main_stops_when_the_loader_file_does_not_run(tmp_path, caplog):
|
|
2005
|
+
"""A loader file with a syntax error: 14, before any reading."""
|
|
2006
|
+
plugin = _loader_file(tmp_path, "class Mine(Loader)\n pass\n")
|
|
2007
|
+
|
|
2008
|
+
code = _run_main_with(
|
|
2009
|
+
["cif2db", "--dic", "a/b", "--loader", plugin, str(tmp_path)],
|
|
2010
|
+
parse_cif_to_db={"side_effect": AssertionError("read a file")},
|
|
2011
|
+
)
|
|
2012
|
+
|
|
2013
|
+
assert code == 14
|
|
2014
|
+
assert f"'{plugin}' can not be loaded: SyntaxError" in caplog.text
|
|
2015
|
+
|
|
2016
|
+
|
|
2004
2017
|
def test_main_stops_when_the_loader_file_has_no_loader(tmp_path, caplog):
|
|
2005
2018
|
"""A plugin without a Loader is a mistake, said before any reading."""
|
|
2006
2019
|
plugin = _loader_file(tmp_path, "X = 1\n")
|
|
@@ -95,17 +95,32 @@ def test_get_config_falls_back_to_the_home_file(home):
|
|
|
95
95
|
assert _config.get_config()["SOURCE"] == "home"
|
|
96
96
|
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
@pytest.mark.parametrize(
|
|
99
|
+
"source", ["file", "$CIFQL_CONFIG_YAML", "default path"]
|
|
100
|
+
)
|
|
101
|
+
def test_get_config_refuses_an_empty_file(home, monkeypatch, source):
|
|
102
|
+
"""An empty file is never what someone meant: ConfigError, wherever it
|
|
103
|
+
came from, no falling through to another source or the defaults."""
|
|
103
104
|
monkeypatch.setenv(
|
|
104
105
|
"CIFQL_CONFIG_YAML", str(write_yaml(home, "env.yaml", "SOURCE: env\n"))
|
|
105
106
|
)
|
|
106
|
-
|
|
107
|
+
if source == "default path":
|
|
108
|
+
monkeypatch.delenv("CIFQL_CONFIG_YAML")
|
|
109
|
+
empty = write_yaml(home, ".cifqlconfig.yaml", "")
|
|
110
|
+
path_to_yaml = None
|
|
111
|
+
elif source == "$CIFQL_CONFIG_YAML":
|
|
112
|
+
empty = write_yaml(home, "empty.yaml", "# nothing but a comment\n")
|
|
113
|
+
monkeypatch.setenv("CIFQL_CONFIG_YAML", str(empty))
|
|
114
|
+
path_to_yaml = None
|
|
115
|
+
else:
|
|
116
|
+
empty = path_to_yaml = write_yaml(home, "empty.yaml", "")
|
|
107
117
|
|
|
108
|
-
|
|
118
|
+
with pytest.raises(_errors.ConfigError) as exc:
|
|
119
|
+
_config.get_config(path_to_yaml=path_to_yaml)
|
|
120
|
+
|
|
121
|
+
assert str(exc.value) == (
|
|
122
|
+
f"Configuration file '{empty}' ({source}) can not be used: it is empty"
|
|
123
|
+
)
|
|
109
124
|
|
|
110
125
|
|
|
111
126
|
def test_get_config_replaces_the_whole_databases_block(home):
|
|
@@ -134,3 +134,61 @@ def test_loader_example_in_the_docs_runs():
|
|
|
134
134
|
|
|
135
135
|
assert result.attempted > 0
|
|
136
136
|
assert result.failed == 0
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@pytest.mark.parametrize(
|
|
140
|
+
"body,message",
|
|
141
|
+
[
|
|
142
|
+
("class Mine(Loader)\n pass\n", "SyntaxError: "),
|
|
143
|
+
("import no_such_module\n", "ModuleNotFoundError: No module named "),
|
|
144
|
+
("X = 1 / 0\n", "ZeroDivisionError: division by zero"),
|
|
145
|
+
],
|
|
146
|
+
ids=["syntax", "import", "runtime"],
|
|
147
|
+
)
|
|
148
|
+
def test_load_loader_refuses_a_file_that_does_not_run(tmp_path, body, message):
|
|
149
|
+
"""A loader file failing to run is a LoaderFileError naming the file and
|
|
150
|
+
what went wrong, not a traceback."""
|
|
151
|
+
plugin = _plugin(tmp_path, body)
|
|
152
|
+
|
|
153
|
+
with pytest.raises(_errors.LoaderFileError) as exc:
|
|
154
|
+
loader.load_loader(plugin)
|
|
155
|
+
|
|
156
|
+
assert str(exc.value).startswith(f"'{plugin}' can not be loaded: {message}")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_load_loader_names_the_line_of_a_syntax_error(tmp_path):
|
|
160
|
+
"""For a syntax error the line is in the message."""
|
|
161
|
+
plugin = _plugin(tmp_path, "X = 1\nclass Mine(Loader)\n pass\n")
|
|
162
|
+
|
|
163
|
+
with pytest.raises(_errors.LoaderFileError, match=r"line 4"):
|
|
164
|
+
loader.load_loader(plugin)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_load_loader_shows_the_traceback_of_the_loader_file(tmp_path):
|
|
168
|
+
"""The message carries the traceback, from the loader file's own lines
|
|
169
|
+
on: its author sees where it failed, Python's import machinery is left
|
|
170
|
+
out."""
|
|
171
|
+
plugin = _plugin(tmp_path, "def f():\n return 1 / 0\n\nf()\n")
|
|
172
|
+
|
|
173
|
+
with pytest.raises(_errors.LoaderFileError) as exc:
|
|
174
|
+
loader.load_loader(plugin)
|
|
175
|
+
|
|
176
|
+
message = str(exc.value)
|
|
177
|
+
assert message.startswith(
|
|
178
|
+
f"'{plugin}' can not be loaded: ZeroDivisionError: division by zero\n"
|
|
179
|
+
+ "Traceback (most recent call last):\n"
|
|
180
|
+
)
|
|
181
|
+
assert f'File "{plugin}", line 6, in <module>' in message
|
|
182
|
+
assert "return 1 / 0" in message
|
|
183
|
+
assert "importlib" not in message
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def test_load_loader_shows_where_the_syntax_is_wrong(tmp_path):
|
|
187
|
+
"""A syntax error: the line and the place in it."""
|
|
188
|
+
plugin = _plugin(tmp_path, "class Mine(Loader)\n pass\n")
|
|
189
|
+
|
|
190
|
+
with pytest.raises(_errors.LoaderFileError) as exc:
|
|
191
|
+
loader.load_loader(plugin)
|
|
192
|
+
|
|
193
|
+
assert f'File "{plugin}", line 3' in str(exc.value)
|
|
194
|
+
assert "^" in str(exc.value)
|
|
@@ -937,6 +937,94 @@ def test_sql_runs_a_select(orm_db):
|
|
|
937
937
|
assert answer["more"] is False
|
|
938
938
|
|
|
939
939
|
|
|
940
|
+
def _refusal(category, lookup):
|
|
941
|
+
"""What a query filtering `category` by `lookup` is told."""
|
|
942
|
+
with pytest.raises(query.QueryError) as exc:
|
|
943
|
+
_explorer().query(category, filters={lookup: "x"})
|
|
944
|
+
|
|
945
|
+
return str(exc.value)
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
def test_query_names_the_category_one_link_further(orm_db):
|
|
949
|
+
"""'_entity_poly' hangs off '_entity', not off 'data_block': the refusal
|
|
950
|
+
names the way, instead of listing what 'data_block' has."""
|
|
951
|
+
message = _refusal("_entity", "datablock__entitypoly__type")
|
|
952
|
+
|
|
953
|
+
assert message == (
|
|
954
|
+
"'datablock__entitypoly__type': 'data_block' has no 'entitypoly', it "
|
|
955
|
+
+ "hangs off '_entity': use 'datablock__entity__entitypoly__type'"
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
def test_query_names_the_spelling_of_a_link(orm_db):
|
|
960
|
+
"""A category written as the dictionary has it, '_entity_poly' or
|
|
961
|
+
'entity_poly': the refusal names the link's spelling."""
|
|
962
|
+
for written in ("entity_poly", "_entity_poly"):
|
|
963
|
+
message = _refusal("_entity", f"{written}__type")
|
|
964
|
+
|
|
965
|
+
assert message == (
|
|
966
|
+
f"'{written}__type': '_entity' has no '{written}', it is called "
|
|
967
|
+
+ "'entitypoly' here: use 'entitypoly__type'"
|
|
968
|
+
)
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
def test_query_names_the_spelling_one_link_further(orm_db):
|
|
972
|
+
"""Spelt as in the dictionary and one link further: way and spelling."""
|
|
973
|
+
message = _refusal("_entity", "datablock__entity_poly__type")
|
|
974
|
+
|
|
975
|
+
assert message == (
|
|
976
|
+
"'datablock__entity_poly__type': 'data_block' has no 'entity_poly', "
|
|
977
|
+
+ "it hangs off '_entity' as 'entitypoly': use "
|
|
978
|
+
+ "'datablock__entity__entitypoly__type'"
|
|
979
|
+
)
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
def test_query_spells_items_exactly(orm_db):
|
|
983
|
+
"""Only links are compared without underscores, an item is not."""
|
|
984
|
+
message = _refusal("_entity", "pdbxnumberofmolecules")
|
|
985
|
+
|
|
986
|
+
assert "It has:" in message
|
|
987
|
+
assert "called" not in message
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
def test_query_names_every_way_one_link_further(orm_db):
|
|
991
|
+
"""Reached through two neighbours: both ways, no list."""
|
|
992
|
+
message = _refusal("_entity", "datablock__pdbxentitynonpoly__comp_id")
|
|
993
|
+
|
|
994
|
+
assert "'data_block' has no 'pdbxentitynonpoly', it hangs off " in message
|
|
995
|
+
assert "'datablock__entity__pdbxentitynonpoly__comp_id'" in message
|
|
996
|
+
assert "'datablock__chem_comps__pdbxentitynonpoly__comp_id'" in message
|
|
997
|
+
assert "It has:" not in message
|
|
998
|
+
spelt = _refusal("_entity", "datablock__pdbx_entity_nonpoly__comp_id")
|
|
999
|
+
assert "it hangs off '_entity' as 'pdbxentitynonpoly' or '_chem_comp' " in (
|
|
1000
|
+
spelt
|
|
1001
|
+
)
|
|
1002
|
+
assert "'datablock__chem_comps__pdbxentitynonpoly__comp_id'" in spelt
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
def test_query_lists_the_names_when_there_are_too_many_ways(orm_db):
|
|
1006
|
+
"""More than a few ways: the list of names, as for a typo."""
|
|
1007
|
+
message = _refusal("_chem_comp_atom", "atom_id_1__cif_id")
|
|
1008
|
+
|
|
1009
|
+
assert "It has:" in message
|
|
1010
|
+
assert "hangs off" not in message
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
def test_query_does_not_point_back_where_it_came_from(orm_db):
|
|
1014
|
+
"""A link back to the category itself is no way further."""
|
|
1015
|
+
message = _refusal("_struct_ref", "structref__db_name")
|
|
1016
|
+
|
|
1017
|
+
assert "hangs off" not in message
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
def test_query_does_not_point_to_the_source_file(orm_db):
|
|
1021
|
+
"""'path' of a data block stays hidden one link further too."""
|
|
1022
|
+
message = _refusal("_entity_poly", "entity_id__path")
|
|
1023
|
+
|
|
1024
|
+
assert "hangs off" not in message
|
|
1025
|
+
assert "path" not in message.split("It has:")[1]
|
|
1026
|
+
|
|
1027
|
+
|
|
940
1028
|
def test_query_does_not_offer_the_source_file(orm_db):
|
|
941
1029
|
"""Where the files lie is the loader's business, not the asker's."""
|
|
942
1030
|
_load()
|
|
@@ -29,6 +29,9 @@ from django.db import OperationalError, connection
|
|
|
29
29
|
|
|
30
30
|
from cifql import _errors, _orm
|
|
31
31
|
|
|
32
|
+
# The ORMs CifQL ships, generated ones in a checkout are left alone.
|
|
33
|
+
SHIPPED_ORMS = ["mmcif_pdbx/v5_417"]
|
|
34
|
+
|
|
32
35
|
# Django is set up once per process, pytest's is taken by the mockup ORM.
|
|
33
36
|
SMOKE_TEST = """
|
|
34
37
|
import sys
|
|
@@ -131,9 +134,15 @@ def test_read_only_opens_sqlite_read_only_and_waits_for_locks():
|
|
|
131
134
|
assert databases["default"]["NAME"] == "/data/pdb.sqlite3"
|
|
132
135
|
|
|
133
136
|
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
|
|
137
|
+
def test_the_shipped_orms_are_there():
|
|
138
|
+
"""The ORMs tested below are in the package; whatever else lies in
|
|
139
|
+
'cifql/dics' of a checkout is not ours to test."""
|
|
140
|
+
available = {f"{dia}/{ver}" for dia, ver in _orm.available_orms()}
|
|
141
|
+
|
|
142
|
+
assert set(SHIPPED_ORMS) <= available
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@pytest.mark.parametrize("orm", SHIPPED_ORMS)
|
|
137
146
|
def test_shipped_orm_passes_djangos_checks_and_builds_its_tables(orm):
|
|
138
147
|
"""The generated code itself is not unit tested, so it must at least load."""
|
|
139
148
|
app, _ = _orm.orm_app(orm)
|
|
@@ -199,7 +208,7 @@ def test_a_database_engine_django_does_not_know_is_a_config_error(tmp_path):
|
|
|
199
208
|
+ " ENGINE: django.db.backends.sqlite4\n NAME: x.sqlite3\n",
|
|
200
209
|
encoding="utf8",
|
|
201
210
|
)
|
|
202
|
-
orm =
|
|
211
|
+
orm = SHIPPED_ORMS[0]
|
|
203
212
|
|
|
204
213
|
result = subprocess.run(
|
|
205
214
|
[
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|