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_propclass_repr_noinit():
p = Properties()
assert repr(p) \
== 'javaproperties.propclass.Properties({!r}, defaults={!r})'\
.format({}, None)
def test_propclass_loadFromXML():
p = Properties()
p.loadFromXML(StringIO(XML_INPUT))
assert len(p) == 4
assert bool(p)
assert dict(p) == {
"foo": "second definition",
"bar": "only definition",
"key": "value",
"zebra": "apple",
}
def test_propclass_empty_setitem(fixed_timestamp):
p = Properties()
p["key"] = "value"
assert len(p) == 1
assert bool(p)
assert dict(p) == {"key": "value"}
s = StringIO()
p.store(s)
assert s.getvalue() == '#' + fixed_timestamp + '\nkey=value\n'
def test_propclass_delitem():
p = Properties()
p.load(StringIO(INPUT))
del p["key"]
assert len(p) == 3
assert bool(p)
assert dict(p) == {
"foo": "second definition",
"bar": "only definition",
"zebra": "apple",
}
def test_propclass_del_nonstring_key():
p = Properties({"key": "value", "apple": "zebra", "foo": "bar"})
with pytest.raises(TypeError) as excinfo:
del p[42]
assert str(excinfo.value) == \
'Keys & values of Properties instances must be strings'
def test_propclass_empty(fixed_timestamp):
p = Properties()
assert len(p) == 0
assert not bool(p)
assert dict(p) == {}
s = StringIO()
p.store(s)
assert s.getvalue() == '#' + fixed_timestamp + '\n'
def test_propclass_eq_repeated_keys():
p = Properties()
p.load(StringIO('key = value\nkey: other value\n'))
p2 = Properties()
p2.load(StringIO('key: whatever\nkey other value'))
assert p == p2
assert dict(p) == dict(p2) == {"key": "other value"}
def test_propclass_from_pairs_list():
p = Properties([("key", "value"), ("apple", "zebra")])
assert len(p) == 2
assert bool(p)
assert dict(p) == {"apple": "zebra", "key": "value"}
def test_propclass_eq_different_comments():
p = Properties()
p.load(StringIO('#This is a comment.\nkey=value\n'))
p2 = Properties()
p2.load(StringIO('#This is also a comment.\nkey=value\n'))
assert p == p2
assert dict(p) == dict(p2)
def test_propclass_defaults_eq_dict():
defs = Properties({"key": "lock", "horse": "orange"})
p = Properties({"Foo": "BAR"}, defaults=defs)
assert p == {"Foo": "BAR"}
assert {"Foo": "BAR"} == p
assert p != {"Foo": "bar"}
assert {"Foo": "bar"} != p