def test_ordered(): from toml import ordered as toml_ordered encoder = toml_ordered.TomlOrderedEncoder() decoder = toml_ordered.TomlOrderedDecoder() o = toml.loads(toml.dumps(TEST_DICT, encoder=encoder), decoder=decoder) assert o == toml.loads(toml.dumps(TEST_DICT, encoder=encoder), decoder=decoder)
def parse_template(path, header='field_name'): if not os.path.exists(path): print('creating file', path) with open(path, "w+") as f: f.write('\n') parsed = toml.load(path, decoder=toml_ordered.TomlOrderedDecoder()) if header not in parsed: parsed[header] = OrderedDict() return parsed[header]
o = loads(dumps(d, encoder=encoder)) assert o == loads(dumps(o, encoder=encoder)) @pytest.mark.parametrize( "encoder_cls", [ pytest.param(toml_ordered.TomlOrderedEncoder, id="type"), pytest.param(toml_ordered.TomlOrderedEncoder(), id="instance"), ] ) @pytest.mark.parametrize( "decoder_cls", [ pytest.param(toml_ordered.TomlOrderedDecoder, id="type"), pytest.param(toml_ordered.TomlOrderedDecoder(), id="instance"), ] ) def test_ordered(encoder_cls, decoder_cls): o: Dict[str, Any] = loads(dumps(TEST_DICT, encoder=encoder_cls), decoder=decoder_cls) assert o == loads(dumps(TEST_DICT, encoder=encoder_cls), decoder=decoder_cls) def test_tuple(): d = {'a': (3, 4)} o: Dict[str, Any] = loads(dumps(d)) assert o == loads(dumps(o)) def test_decimal(): PLACES = Decimal(10)**-4