Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_propfile_neq_string():
pf = PropertiesFile.loads('key = value\nkey: other value\n')
assert pf != 'key = value\nkey: other value\n'
assert 'key = value\nkey: other value\n' != pf
def test_propfile_getitem():
pf = PropertiesFile.loads(INPUT)
pf._check()
assert pf["key"] == "value"
assert pf["foo"] == "second definition"
with pytest.raises(KeyError):
pf["missing"]
pf._check()
def test_propfile_set_nochange():
pf = PropertiesFile.loads(INPUT)
pf._check()
assert pf["key"] == "value"
pf["key"] = "value"
pf._check()
assert dict(pf) == {
"foo": "second definition",
"bar": "only definition",
"key": "value",
"zebra": "apple",
}
assert list(pf) == ["foo", "bar", "key", "zebra"]
assert list(reversed(pf)) == ["zebra", "key", "bar", "foo"]
assert pf.dumps() == '''\
# A comment before the timestamp
def test_propfile_eq_set_nochange():
pf = PropertiesFile.loads(INPUT)
pf2 = PropertiesFile.loads(INPUT)
assert pf == pf2
assert pf["key"] == pf2["key"] == "value"
pf2["key"] = "value"
assert pf == pf2
assert dict(pf) == dict(pf2)
assert pf.dumps() == INPUT
assert pf.dumps() != pf2.dumps()
def test_propfile_eq_one_repeated_key():
pf = PropertiesFile.loads('key = value\nkey: other value\n')
pf2 = PropertiesFile.loads('key other value')
assert pf == pf2
assert dict(pf) == dict(pf2) == {"key": "other value"}
def test_propfile_eq_self():
pf = PropertiesFile.loads(INPUT)
assert pf == pf
def test_propfile_preserve_trailing_escape():
pf = PropertiesFile.loads('key = value\\')
pf._check()
assert dict(pf) == {"key": "value"}
assert pf.dumps() == 'key = value\\'
def test_propfile_eq_repeated_keys():
pf = PropertiesFile.loads('key = value\nkey: other value\n')
pf2 = PropertiesFile.loads('key: whatever\nkey other value')
assert pf == pf2
assert dict(pf) == dict(pf2) == {"key": "other value"}
def test_propfile_add_after_trailing_escape():
pf = PropertiesFile.loads('key = value\\')
pf._check()
pf["new"] = "old"
pf._check()
assert dict(pf) == {"key": "value", "new": "old"}
assert pf.dumps() == 'key = value\nnew=old\n'
def test_propfile_neq_different_comments():
pf = PropertiesFile.loads('#This is a comment.\nkey=value\n')
pf2 = PropertiesFile.loads('#This is also a comment.\nkey=value\n')
assert pf != pf2
assert dict(pf) == dict(pf2)