Skip to content

Commit 4febff2

Browse files
authored
Merge pull request #50 from CitrineInformatics/release/0.3.0
Taurus v0.3.0 is released!
2 parents b416696 + 812c0ac commit 4febff2

File tree

6 files changed

+896
-11
lines changed

6 files changed

+896
-11
lines changed

setup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def run(self):
3636

3737

3838
setup(name='taurus-citrine',
39-
version='0.2.1',
39+
version='0.3.0',
4040
url='http://github.com/CitrineInformatics/taurus',
4141
description='Python library for the Citrine Platform',
4242
author='Max Hutchinson',
@@ -45,7 +45,8 @@ def run(self):
4545
package_data={
4646
'taurus': [
4747
'demo/strehlow_and_cook.json',
48-
'units/citrine_en.txt'
48+
'units/citrine_en.txt',
49+
'units/constants_en.txt'
4950
]
5051
},
5152
install_requires=[

taurus/client/tests/test_json.py

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from taurus.entity.object import MeasurementRun, MaterialRun, ProcessRun, MeasurementSpec
1212
from taurus.entity.object.ingredient_run import IngredientRun
1313
from taurus.entity.object.ingredient_spec import IngredientSpec
14+
from taurus.entity.value.nominal_integer import NominalInteger
1415
from taurus.entity.value.nominal_real import NominalReal
1516
from taurus.entity.value.normal_real import NormalReal
1617
from taurus.enumeration.origin import Origin
@@ -52,6 +53,12 @@ def test_deserialize():
5253
assert(copy_meas.uids["auto"] == measurement.uids["auto"])
5354

5455

56+
def test_deserialize_extra_fields():
57+
"""Extra JSON fields should be ignored in deserialization."""
58+
json_data = '[[], {"nominal": 5, "type": "nominal_integer", "extra garbage": "foo"}]'
59+
assert(loads(json_data) == NominalInteger(nominal=5))
60+
61+
5562
def test_enumeration_serde():
5663
"""An enumeration should get serialized as a string."""
5764
condition = Condition(name="A condition", notes=Origin.UNKNOWN)

taurus/entity/dict_serializable.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
from abc import ABC
2+
from logging import getLogger
3+
24
import json
5+
import inspect
6+
7+
# There are some weird (probably resolvable) errors during object cloning if this is an
8+
# instance variable of DictSerializable.
9+
logger = getLogger(__name__)
310

411

512
class DictSerializable(ABC):
@@ -24,10 +31,18 @@ def from_dict(cls, d):
2431
The deserialized object.
2532
2633
"""
34+
expected_arg_names = inspect.getfullargspec(cls.__init__).args
35+
kwargs = {}
36+
for name, arg in d.items():
37+
if name in expected_arg_names:
38+
kwargs[name] = arg
39+
else:
40+
logger.warning('Ignoring unexpected keyword argument in {}: {}'.format(
41+
cls.__name__, name))
2742
# noinspection PyArgumentList
2843
# DictSerializable's constructor is not intended for use,
2944
# but all of its children will use from_dict like this.
30-
return cls(**d)
45+
return cls(**kwargs)
3146

3247
def as_dict(self):
3348
"""

0 commit comments

Comments
 (0)