def test_propfile_from_pairs_list(): pf = PropertiesFile([('key', 'value'), ('apple', 'zebra')]) pf._check() assert len(pf) == 2 assert bool(pf) assert dict(pf) == {"apple": "zebra", "key": "value"} assert list(pf) == ["key", "apple"] assert list(reversed(pf)) == ["apple", "key"] assert pf.dumps() == 'key=value\napple=zebra\n'
def test_propfile_from_kwarg(): pf = PropertiesFile(key='value') pf._check() assert len(pf) == 1 assert bool(pf) assert dict(pf) == {"key": "value"} assert list(pf) == ["key"] assert list(reversed(pf)) == ["key"] assert pf.dumps() == 'key=value\n'
def test_propfile_empty(): pf = PropertiesFile() pf._check() assert len(pf) == 0 assert not bool(pf) assert dict(pf) == {} assert list(pf) == [] assert list(reversed(pf)) == [] assert pf.dumps() == ''
def test_propfile_from_ordereddict_and_kwarg(): pf = PropertiesFile(OrderedDict([('key', 'value'), ('apple', 'zebra')]), key='lock') pf._check() assert len(pf) == 2 assert bool(pf) assert dict(pf) == {"apple": "zebra", "key": "lock"} assert list(pf) == ["key", "apple"] assert list(reversed(pf)) == ["apple", "key"] assert pf.dumps() == 'key=lock\napple=zebra\n'
def test_propfile_empty_setitem(): pf = PropertiesFile() pf._check() pf["key"] = "value" pf._check() assert len(pf) == 1 assert bool(pf) assert dict(pf) == {"key": "value"} assert list(pf) == ["key"] assert list(reversed(pf)) == ["key"] assert pf.dumps() == 'key=value\n'
def test_propfile_copy(): pf = PropertiesFile({"Foo": "bar"}) pf2 = pf.copy() pf._check() pf2._check() assert pf is not pf2 assert isinstance(pf2, PropertiesFile) assert pf == pf2 assert dict(pf) == dict(pf2) == {"Foo": "bar"} pf2["Foo"] = "gnusto" pf._check() pf2._check() assert dict(pf) == {"Foo": "bar"} assert dict(pf2) == {"Foo": "gnusto"} assert pf != pf2 pf2["fOO"] = "quux" pf._check() pf2._check() assert dict(pf) == {"Foo": "bar"} assert dict(pf2) == {"Foo": "gnusto", "fOO": "quux"} assert pf != pf2