gemd 2.1.1__tar.gz → 2.1.4__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.
- {gemd-2.1.1 → gemd-2.1.4}/PKG-INFO +10 -12
- {gemd-2.1.1 → gemd-2.1.4}/README.md +1 -1
- gemd-2.1.4/gemd/__version__.py +1 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/strehlow_and_cook.py +1 -1
- {gemd-2.1.1 → gemd-2.1.4}/gemd/units/impl.py +1 -1
- {gemd-2.1.1 → gemd-2.1.4}/gemd.egg-info/PKG-INFO +10 -12
- {gemd-2.1.1 → gemd-2.1.4}/gemd.egg-info/SOURCES.txt +5 -1
- {gemd-2.1.1 → gemd-2.1.4}/gemd.egg-info/requires.txt +7 -2
- gemd-2.1.4/gemd.egg-info/top_level.txt +2 -0
- {gemd-2.1.1 → gemd-2.1.4}/setup.py +15 -12
- gemd-2.1.4/tests/__init__.py +0 -0
- gemd-2.1.4/tests/units/__init__.py +0 -0
- gemd-2.1.4/tests/units/test_parser.py +225 -0
- gemd-2.1.4/tests/units/test_units.txt +4 -0
- gemd-2.1.1/gemd/__version__.py +0 -1
- gemd-2.1.1/gemd.egg-info/top_level.txt +0 -1
- {gemd-2.1.1 → gemd-2.1.4}/LICENSE +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/builders/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/builders/impl.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/cake.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/material_run_example.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/measurement_example.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/strehlow_and_cook.pif +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/strehlow_and_cook_small.pif +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/table_example.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/demo/toothpick.jpg +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/attribute/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/attribute/base_attribute.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/attribute/condition.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/attribute/parameter.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/attribute/property.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/attribute/property_and_conditions.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/base_entity.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/base_bounds.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/categorical_bounds.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/composition_bounds.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/integer_bounds.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/molecular_structure_bounds.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds/real_bounds.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/bounds_validation.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/case_insensitive_dict.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/dict_serializable.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/file_link.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/has_dependencies.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/link_by_uid.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/base_object.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_conditions.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_material.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_parameters.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_process.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_properties.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_quantities.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_source.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_spec.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/has_template_check_generator.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/ingredient_run.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/ingredient_spec.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/material_run.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/material_spec.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/measurement_run.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/measurement_spec.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/process_run.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/object/process_spec.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/setters.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/source/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/source/performed_source.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/attribute_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/base_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/condition_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/has_condition_templates.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/has_parameter_templates.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/has_property_templates.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/material_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/measurement_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/parameter_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/process_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/template/property_template.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/util.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/valid_list.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/base_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/categorical_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/composition_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/continuous_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/discrete_categorical.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/empirical_formula.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/inchi_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/integer_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/molecular_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/nominal_categorical.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/nominal_composition.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/nominal_integer.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/nominal_real.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/normal_real.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/smiles_value.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/uniform_integer.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/entity/value/uniform_real.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/enumeration/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/enumeration/base_enumeration.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/enumeration/origin.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/enumeration/sample_type.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/json/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/json/gemd_encoder.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/json/gemd_json.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/units/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/units/citrine_en.txt +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/units/constants_en.txt +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/util/__init__.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd/util/impl.py +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/gemd.egg-info/dependency_links.txt +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/setup.cfg +0 -0
- {gemd-2.1.1 → gemd-2.1.4}/tests/test_examples.py +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gemd
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
4
4
|
Summary: Python binding for Citrine's GEMD data model
|
|
5
5
|
Home-page: http://github.com/CitrineInformatics/gemd-python
|
|
6
6
|
Author: Citrine Informatics
|
|
7
|
+
License: UNKNOWN
|
|
8
|
+
Platform: UNKNOWN
|
|
7
9
|
Classifier: Programming Language :: Python :: 3
|
|
8
10
|
Classifier: Programming Language :: Python :: 3.8
|
|
9
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -11,15 +13,11 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
11
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
15
|
Requires-Python: >=3.8
|
|
14
|
-
|
|
15
|
-
Requires-Dist: pint<0.24,>=0.20
|
|
16
|
-
Requires-Dist: deprecation<3,>=2.1.0
|
|
17
|
-
Requires-Dist: typing_extensions<5,>=4.8
|
|
18
|
-
Requires-Dist: importlib-resources<7,>=5.3
|
|
16
|
+
Provides-Extra: scripts
|
|
19
17
|
Provides-Extra: tests
|
|
20
|
-
|
|
21
|
-
Provides-Extra: tests
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
Provides-Extra: tests.demo
|
|
19
|
+
Provides-Extra: tests.entity.bounds
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
|
|
22
|
+
UNKNOWN
|
|
23
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# GEMD-python
|
|
2
|
-
Python binding for Citrine's
|
|
2
|
+
Python binding for Citrine's data model, GEMD.
|
|
3
3
|
|
|
4
4
|
This package provides a framework for storing information about the processes that create materials, the materials themselves, and measurements performed on those materials.
|
|
5
5
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.1.4"
|
|
@@ -48,7 +48,7 @@ def import_table(filename=SMALL_TABLE):
|
|
|
48
48
|
from importlib_resources import files
|
|
49
49
|
import json
|
|
50
50
|
|
|
51
|
-
return json.loads(files("gemd.demo").joinpath(filename).read_text())
|
|
51
|
+
return json.loads(files("gemd.demo").joinpath(filename).read_text(encoding='utf-8'))
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
def _fingerprint(row):
|
|
@@ -35,7 +35,7 @@ def _deploy_default_files() -> Tuple[Path, Path]:
|
|
|
35
35
|
target_paths = tuple(target_dir / f for f in ("citrine_en.txt", "constants_en.txt"))
|
|
36
36
|
for target in target_paths:
|
|
37
37
|
source = resources.joinpath(target.name)
|
|
38
|
-
target.
|
|
38
|
+
target.write_bytes(source.read_bytes())
|
|
39
39
|
|
|
40
40
|
return target_paths
|
|
41
41
|
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gemd
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
4
4
|
Summary: Python binding for Citrine's GEMD data model
|
|
5
5
|
Home-page: http://github.com/CitrineInformatics/gemd-python
|
|
6
6
|
Author: Citrine Informatics
|
|
7
|
+
License: UNKNOWN
|
|
8
|
+
Platform: UNKNOWN
|
|
7
9
|
Classifier: Programming Language :: Python :: 3
|
|
8
10
|
Classifier: Programming Language :: Python :: 3.8
|
|
9
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
@@ -11,15 +13,11 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
11
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
15
|
Requires-Python: >=3.8
|
|
14
|
-
|
|
15
|
-
Requires-Dist: pint<0.24,>=0.20
|
|
16
|
-
Requires-Dist: deprecation<3,>=2.1.0
|
|
17
|
-
Requires-Dist: typing_extensions<5,>=4.8
|
|
18
|
-
Requires-Dist: importlib-resources<7,>=5.3
|
|
16
|
+
Provides-Extra: scripts
|
|
19
17
|
Provides-Extra: tests
|
|
20
|
-
|
|
21
|
-
Provides-Extra: tests
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
Provides-Extra: tests.demo
|
|
19
|
+
Provides-Extra: tests.entity.bounds
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
|
|
22
|
+
UNKNOWN
|
|
23
|
+
|
|
@@ -108,4 +108,8 @@ gemd/units/constants_en.txt
|
|
|
108
108
|
gemd/units/impl.py
|
|
109
109
|
gemd/util/__init__.py
|
|
110
110
|
gemd/util/impl.py
|
|
111
|
-
tests/
|
|
111
|
+
tests/__init__.py
|
|
112
|
+
tests/test_examples.py
|
|
113
|
+
tests/units/__init__.py
|
|
114
|
+
tests/units/test_parser.py
|
|
115
|
+
tests/units/test_units.txt
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
pint<0.24,>=0.20
|
|
2
1
|
deprecation<3,>=2.1.0
|
|
3
|
-
typing_extensions<5,>=4.8
|
|
4
2
|
importlib-resources<7,>=5.3
|
|
3
|
+
pint<0.24,>=0.20
|
|
4
|
+
typing_extensions<5,>=4.8
|
|
5
|
+
|
|
6
|
+
[scripts]
|
|
7
|
+
packagingsphinx==5.0.0
|
|
8
|
+
sphinx-rtd-theme==1.0.0
|
|
9
|
+
sphinxcontrib-apidoc==0.3.0
|
|
5
10
|
|
|
6
11
|
[tests]
|
|
7
12
|
pytest<9,>=8.0.0
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
from setuptools import setup, find_packages
|
|
2
|
-
from
|
|
3
|
-
from packaging.version import Version
|
|
2
|
+
from pathlib import Path
|
|
4
3
|
import re
|
|
5
4
|
|
|
6
5
|
packages = find_packages()
|
|
7
6
|
|
|
8
|
-
this_directory =
|
|
9
|
-
version_file =
|
|
10
|
-
version_re = r'''
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
else:
|
|
16
|
-
raise RuntimeError(f"Unable to find version string in {version_file}")
|
|
7
|
+
this_directory = Path(__file__).parent.absolute()
|
|
8
|
+
version_file = this_directory / 'gemd' / '__version__.py'
|
|
9
|
+
version_re = r'''^\s*__version__\s*=\s*(['"])([\w\.]+)\1$'''
|
|
10
|
+
if mo := re.search(version_re, version_file.read_text(), re.M):
|
|
11
|
+
version = mo.group(2)
|
|
12
|
+
else:
|
|
13
|
+
raise RuntimeError(f"Unable to find version string in {version_file}")
|
|
17
14
|
|
|
18
15
|
setup(name='gemd',
|
|
19
16
|
# Update this in gemd/__version__.py
|
|
20
|
-
version=
|
|
17
|
+
version=version,
|
|
21
18
|
python_requires='>=3.8',
|
|
22
19
|
url='http://github.com/CitrineInformatics/gemd-python',
|
|
23
20
|
description="Python binding for Citrine's GEMD data model",
|
|
@@ -42,6 +39,12 @@ setup(name='gemd',
|
|
|
42
39
|
"importlib-resources>=5.3,<7"
|
|
43
40
|
],
|
|
44
41
|
extras_require={
|
|
42
|
+
"scripts": [
|
|
43
|
+
"packaging"
|
|
44
|
+
"sphinx==5.0.0",
|
|
45
|
+
"sphinx-rtd-theme==1.0.0",
|
|
46
|
+
"sphinxcontrib-apidoc==0.3.0",
|
|
47
|
+
],
|
|
45
48
|
"tests": [
|
|
46
49
|
"pytest>=8.0.0,<9"
|
|
47
50
|
],
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
from deprecation import DeprecatedWarning
|
|
3
|
+
from importlib_resources import files
|
|
4
|
+
import re
|
|
5
|
+
from pint import UnitRegistry
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from gemd.units import parse_units, convert_units, get_base_units, change_definitions_file, \
|
|
9
|
+
UndefinedUnitError, DefinitionSyntaxError, IncompatibleUnitsError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.mark.parametrize("return_unit", [True, False])
|
|
13
|
+
def test_parse_expected(return_unit):
|
|
14
|
+
"""Test that we can parse the units that we expect to be able to."""
|
|
15
|
+
# Pint's parse_units actually gets this wrong
|
|
16
|
+
assert parse_units("m^-1 * newton / meter", return_unit=return_unit) == \
|
|
17
|
+
parse_units("N / m^2", return_unit=return_unit)
|
|
18
|
+
|
|
19
|
+
expected = [
|
|
20
|
+
"degC", "degF", "K",
|
|
21
|
+
"g", "kg", "mg", "ton",
|
|
22
|
+
"L", "mL",
|
|
23
|
+
"inch", "ft", "mm", "um",
|
|
24
|
+
"second", "ms", "hour", "minute", "ns",
|
|
25
|
+
"g/cm^3", "g/mL", "kg/cm^3",
|
|
26
|
+
"", "1",
|
|
27
|
+
"amu", # A line that was edited
|
|
28
|
+
"Seconds", # Added support for some title-case units
|
|
29
|
+
"delta_Celsius / hour", # Added to make sure pint version is right (>0.10)
|
|
30
|
+
"g / 2.5 cm", # Scaling factors are acceptable
|
|
31
|
+
"g / -+-25e-1 m", # Weird but fine
|
|
32
|
+
"ug / - -250 mL", # Spaces between unaries is acceptable
|
|
33
|
+
"1 / 10**5 degC", # Spaces between unaries is acceptable
|
|
34
|
+
"1 / 10_000 degC", # Spaces between unaries is acceptable
|
|
35
|
+
"m ** - 1", # Pint < 0.21 throws DefinitionSyntaxError
|
|
36
|
+
"gram / _10_minute", # Stringified Unit object SPT-1311
|
|
37
|
+
"gram / __1_2e_3minute", # Stringified Unit object SPT-1311
|
|
38
|
+
]
|
|
39
|
+
for unit in expected:
|
|
40
|
+
parsed = parse_units(unit, return_unit=return_unit)
|
|
41
|
+
assert parsed == parse_units(parsed, return_unit=return_unit)
|
|
42
|
+
assert parse_units("") == 'dimensionless'
|
|
43
|
+
# Scaling factors bind tightly to trailing units
|
|
44
|
+
scaling = [
|
|
45
|
+
("g / 2.5 cm", "g / (2.5 cm)"),
|
|
46
|
+
("g / 2.5cm", "g / (2.5 cm)"),
|
|
47
|
+
("g / 25.mm", "g / (25. mm)"),
|
|
48
|
+
("g / 2.5 * cm", "g cm / 2.5")
|
|
49
|
+
]
|
|
50
|
+
for left, right in scaling:
|
|
51
|
+
assert parse_units(left, return_unit=return_unit) == \
|
|
52
|
+
parse_units(right, return_unit=return_unit)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_parse_unexpected():
|
|
56
|
+
"""Test that we cannot parse the units that we do not expect to."""
|
|
57
|
+
unexpected = [
|
|
58
|
+
"gibberish",
|
|
59
|
+
5,
|
|
60
|
+
"cp", # Removed because of risk of collision with cP
|
|
61
|
+
"chain", # Survey units eliminated
|
|
62
|
+
"SECONDS", # Not just case insensitivity
|
|
63
|
+
"lb : in^3", # : is not a valid operator
|
|
64
|
+
]
|
|
65
|
+
for unit in unexpected:
|
|
66
|
+
with pytest.raises(UndefinedUnitError):
|
|
67
|
+
parse_units(unit)
|
|
68
|
+
|
|
69
|
+
scaling = [
|
|
70
|
+
"3 rpm", # No leading digits
|
|
71
|
+
"16", # No values that are just integers
|
|
72
|
+
"16.2" # No values that are just floats
|
|
73
|
+
"g * 0/ m", # Zero scaling factor
|
|
74
|
+
"F * 1.1 3.5", # numeric syntax error
|
|
75
|
+
"F m 1.1", # scale follows unit
|
|
76
|
+
"F * 1.1 ** 2", # numeric syntax error
|
|
77
|
+
]
|
|
78
|
+
for unit in scaling:
|
|
79
|
+
with pytest.raises(ValueError, match=r"[sS]caling"):
|
|
80
|
+
parse_units(unit)
|
|
81
|
+
|
|
82
|
+
definition = [
|
|
83
|
+
"/gram", # A leading operator makes no sense
|
|
84
|
+
]
|
|
85
|
+
for unit in definition:
|
|
86
|
+
with pytest.raises(DefinitionSyntaxError):
|
|
87
|
+
parse_units(unit)
|
|
88
|
+
|
|
89
|
+
zero_division = [
|
|
90
|
+
"g / 0 m", # Division by zero
|
|
91
|
+
]
|
|
92
|
+
for unit in zero_division:
|
|
93
|
+
with pytest.raises(ZeroDivisionError):
|
|
94
|
+
parse_units(unit)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_parse_none():
|
|
98
|
+
"""Test that None parses as None."""
|
|
99
|
+
assert parse_units(None) is None
|
|
100
|
+
assert parse_units(None, return_unit=True) == parse_units("", return_unit=True)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_parse_units_as_units():
|
|
104
|
+
"""Test that Units in == Units out."""
|
|
105
|
+
from gemd.units.impl import _REGISTRY
|
|
106
|
+
|
|
107
|
+
expected = [
|
|
108
|
+
_REGISTRY("kg").u,
|
|
109
|
+
]
|
|
110
|
+
for unit in expected:
|
|
111
|
+
parsed = parse_units(unit)
|
|
112
|
+
assert parsed == parse_units(parsed)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_format():
|
|
116
|
+
"""Test that custom formatting behaves as we hope."""
|
|
117
|
+
# use the default unit registry for now
|
|
118
|
+
reg = UnitRegistry()
|
|
119
|
+
|
|
120
|
+
result = parse_units("K^-2.0 m^-1e0 C^0 g^1 s^2")
|
|
121
|
+
assert "-" not in result
|
|
122
|
+
assert "[time]" in str(reg(result).dimensionality)
|
|
123
|
+
assert "[current]" not in str(reg(result).dimensionality)
|
|
124
|
+
kelvin = str(reg("K").units)
|
|
125
|
+
gram = str(reg("g").units)
|
|
126
|
+
second = str(reg("s").units)
|
|
127
|
+
assert kelvin in str(result)
|
|
128
|
+
assert gram in str(result)
|
|
129
|
+
assert second in str(result)
|
|
130
|
+
assert result.index(gram) < result.index(kelvin)
|
|
131
|
+
assert result.index(gram) < result.index(second)
|
|
132
|
+
|
|
133
|
+
assert not re.search(r"\d", parse_units("m kg / s"))
|
|
134
|
+
assert "/" not in parse_units("m kg s")
|
|
135
|
+
assert "1" not in parse_units("s")
|
|
136
|
+
assert "1" in parse_units("s^-1")
|
|
137
|
+
assert "2.5" in parse_units("g / 2.5 cm")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_conversion():
|
|
141
|
+
"""Tests that check if particular units are interoperable."""
|
|
142
|
+
conversions = {"in_lb": "foot_pound"}
|
|
143
|
+
for source, dest in conversions.items():
|
|
144
|
+
assert convert_units(convert_units(1, source, dest), dest, source) == 1
|
|
145
|
+
|
|
146
|
+
# Verify that convert_units respects scaling factors
|
|
147
|
+
assert -1e-8 < convert_units(100, 'g / 100 mL', 'g/cc') - 1 < 1e-8
|
|
148
|
+
assert -1e-8 < convert_units(1, "g / 2.5 cm", "g / 25 mm") - 1 < 1e-8
|
|
149
|
+
|
|
150
|
+
# Verify that convert_units throws exceptions
|
|
151
|
+
with pytest.raises(IncompatibleUnitsError):
|
|
152
|
+
convert_units(1, 'mL', 'g')
|
|
153
|
+
with pytest.raises(IncompatibleUnitsError):
|
|
154
|
+
# https://pint.readthedocs.io/en/0.23/user/angular_frequency.html
|
|
155
|
+
convert_units(1, 'Hz', 'rpm')
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_get_base_units():
|
|
159
|
+
"""Test that base units & conversions make sense."""
|
|
160
|
+
from gemd.units.impl import _REGISTRY
|
|
161
|
+
assert get_base_units("degC") == (_REGISTRY("kelvin"), 1, 273.15)
|
|
162
|
+
assert get_base_units("degC") == get_base_units(_REGISTRY("degC"))
|
|
163
|
+
assert get_base_units("km") == (_REGISTRY("meter"), 1000, 0)
|
|
164
|
+
assert get_base_units("g / 25 mm") == (_REGISTRY("kg / m"), 0.04, 0)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@contextmanager
|
|
168
|
+
def _change_units(filename):
|
|
169
|
+
try:
|
|
170
|
+
change_definitions_file(filename)
|
|
171
|
+
yield
|
|
172
|
+
finally:
|
|
173
|
+
change_definitions_file()
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def test_file_change(tmpdir):
|
|
177
|
+
"""Test that swapping units files works."""
|
|
178
|
+
assert convert_units(1, 'm', 'cm') == 100
|
|
179
|
+
with pytest.raises(UndefinedUnitError):
|
|
180
|
+
assert convert_units(1, 'usd', 'USD') == 1
|
|
181
|
+
|
|
182
|
+
test_file = tmpdir / "test_units.txt"
|
|
183
|
+
test_file.write_binary(files("tests.units").joinpath("test_units.txt").read_bytes())
|
|
184
|
+
with _change_units(filename=test_file):
|
|
185
|
+
with pytest.raises(UndefinedUnitError):
|
|
186
|
+
assert convert_units(1, 'm', 'cm') == 100
|
|
187
|
+
assert convert_units(1, 'usd', 'USD') == 1
|
|
188
|
+
assert convert_units(1, 'm', 'cm') == 100 # And verify we're back to normal
|
|
189
|
+
with pytest.raises(UndefinedUnitError):
|
|
190
|
+
parse_units('mol : mol') # Ensure the preprocessor is still there
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_punctuation():
|
|
194
|
+
"""Test that punctuation parses reasonably."""
|
|
195
|
+
assert parse_units('mol.') == parse_units('moles')
|
|
196
|
+
assert parse_units('N.m') == parse_units('N * m')
|
|
197
|
+
with pytest.raises(UndefinedUnitError):
|
|
198
|
+
parse_units('mol : mol')
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def test_exponents():
|
|
202
|
+
"""SPT-874 fractional exponents were being treated as zero."""
|
|
203
|
+
megapascals = parse_units("MPa")
|
|
204
|
+
sqrt_megapascals = parse_units('MPa^0.5')
|
|
205
|
+
assert megapascals in sqrt_megapascals
|
|
206
|
+
assert sqrt_megapascals == parse_units(f"{megapascals} / {sqrt_megapascals}")
|
|
207
|
+
assert parse_units('MPa^1.5') == parse_units(f"{megapascals} * {sqrt_megapascals}")
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def test__scientific_notation_preprocessor():
|
|
211
|
+
"""Verify that numbers are converted into scientific notation."""
|
|
212
|
+
assert "1e2 kilogram" in parse_units("F* 10 ** 2 kg")
|
|
213
|
+
assert "1e2 kg" in f'{parse_units("F* 10 ** 2 kg", return_unit=True):~}'
|
|
214
|
+
assert "1e-5" in parse_units("F* mm*10**-5")
|
|
215
|
+
assert "1e" not in parse_units("F* kg * 10 cm")
|
|
216
|
+
assert "-3.07e2" in parse_units("F* -3.07 * 10 ** 2")
|
|
217
|
+
assert "11e2" in parse_units("F* 11*10^2")
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def test_deprecation():
|
|
221
|
+
"""Make sure deprecated things warn correctly."""
|
|
222
|
+
megapascals = parse_units("MPa", return_unit=True)
|
|
223
|
+
with pytest.warns(DeprecatedWarning):
|
|
224
|
+
stringified = f"{megapascals:clean}"
|
|
225
|
+
assert megapascals == parse_units(stringified, return_unit=True)
|
gemd-2.1.1/gemd/__version__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.1.1"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
gemd
|
|
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
|
|
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
|
|
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
|