def test_docs_table_any(): class Table(object): def __init__(self, height, width): self.height = height self.width = width def __repr__(self): return "<Table {self.height!r}x{self.width!r}>".format(self=self) from camel import Camel, CamelRegistry my_types = CamelRegistry() @my_types.loader('table', version=any) def _load_table(data, version): if 'size' in data: # version 1 edge = data['size']**0.5 return Table(edge, edge) else: # version 2?) return Table(data['height'], data['width']) camel = Camel([my_types]) table1, table2 = camel.load( "[!table;1 {size: 49}, !table;2 {height: 5, width: 9}]") assert table1.height == 7 assert table1.width == 7 assert table2.height == 5 assert table2.width == 9
def test_docs_table_any(): class Table(object): def __init__(self, height, width): self.height = height self.width = width def __repr__(self): return "<Table {self.height!r}x{self.width!r}>".format(self=self) from camel import Camel, CamelRegistry my_types = CamelRegistry() @my_types.loader('table', version=any) def _load_table(data, version): if 'size' in data: # version 1 edge = data['size'] ** 0.5 return Table(edge, edge) else: # version 2?) return Table(data['height'], data['width']) camel = Camel([my_types]) table1, table2 = camel.load( "[!table;1 {size: 49}, !table;2 {height: 5, width: 9}]") assert table1.height == 7 assert table1.width == 7 assert table2.height == 5 assert table2.width == 9
def test_python_roundtrip(value, expected_serialization): camel = Camel([PYTHON_TYPES]) dumped = camel.dump(value) assert dumped == expected_serialization # Should be able to load them without the python types vanilla_camel = Camel() assert vanilla_camel.load(dumped) == value
def test_frozenset_roundtrip(): # By default, frozensets become sets value = frozenset((4, 3, 2)) camel = Camel() dumped = camel.dump(value) # TODO this should use ? notation assert dumped == "!!set\n2: null\n3: null\n4: null\n" assert camel.load(dumped) == set(value)
def test_tuple_roundtrip(): # By default, tuples become lists value = (4, 3, 2) camel = Camel() dumped = camel.dump(value) # TODO short list like this should be flow style? assert dumped == "- 4\n- 3\n- 2\n" assert camel.load(dumped) == list(value)
def test_docs_deleted(): class DummyData(object): def __init__(self, data): self.data = data from camel import Camel, CamelRegistry my_types = CamelRegistry() @my_types.loader('deleted-type', version=all) def _load_deleted_type(data, version): return DummyData(data) camel = Camel([my_types]) assert isinstance(camel.load("""!deleted-type;4 foo"""), DummyData)
def test_basic_roundtrip(value, expected_serialization): camel = Camel() dumped = camel.dump(value) assert dumped == expected_serialization assert camel.load(dumped) == value
def test_dieroll(): value = DieRoll(3, 6) camel = Camel([reg]) dumped = camel.dump(value) assert dumped == '!roll 3d6\n...\n' assert camel.load(dumped) == value
Point( 53.095943, -2.469436, # a nice spot in the middle of Valley Brook srid=4326, ), experience=0)) if __name__ == '__main__': from sys import argv camel = Camel([registry]) try: with open('cli-duck.yaml', 'r') as f: duck = camel.load(f.read()) except FileNotFoundError: duck = _sample_duck() if duck.success is not None: print('your saved journey ended, starting a new one...') duck = Duck.make_successor() response = ' '.join(argv[1:]) or None advancement = duck.advance(response=response) print(duck.progress_summary(), end='\n\n') if advancement is None: if duck.scenario is None: print('there is nothing to be done right now, come back when the '
def test_dieroll2(): value = DieRoll(3, 6) camel = Camel([reg2]) dumped = camel.dump(value) assert dumped == '!roll\nnumdice: 3\nfaces: 6\n' assert camel.load(dumped) == value