Skip to content

Instantly share code, notes, and snippets.

@mgood
Created May 29, 2015 21:21
Show Gist options
  • Save mgood/74e376102e9e45faf433 to your computer and use it in GitHub Desktop.
Save mgood/74e376102e9e45faf433 to your computer and use it in GitHub Desktop.
jproperties functional tests
$ py.test
============================= test session starts ==============================
platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.1
rootdir: /Users/matt/Projects/jprops/.venv/jprops/src/jproperties, inifile:
plugins: xdist
collected 66 items
test_functional.py ........FFFFFF...F.........FFF.FFFFFFFFFF....F...F.FFFFFF.F...FFFF
=================================== FAILURES ===================================
__________________________ test_load[a : : b-props8] ___________________________
data = 'a : : b', props = {'a': ': b'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': 'b'} == {'a': ': b'}
E Differing items:
E {'a': 'b'} != {'a': ': b'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
____________________________ test_load[a::b-props9] ____________________________
data = 'a::b', props = {'a': ':b'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': 'b'} == {'a': ':b'}
E Differing items:
E {'a': 'b'} != {'a': ':b'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
__________________________ test_load[a = = b-props10] __________________________
data = 'a = = b', props = {'a': '= b'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': 'b'} == {'a': '= b'}
E Differing items:
E {'a': 'b'} != {'a': '= b'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
___________________________ test_load[a==b-props11] ____________________________
data = 'a==b', props = {'a': '=b'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': 'b'} == {'a': '=b'}
E Differing items:
E {'a': 'b'} != {'a': '=b'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
__________________________ test_load[a = : b-props12] __________________________
data = 'a = : b', props = {'a': ': b'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': 'b'} == {'a': ': b'}
E Differing items:
E {'a': 'b'} != {'a': ': b'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
__________________________ test_load[a : = b-props13] __________________________
data = 'a : = b', props = {'a': '= b'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': 'b'} == {'a': '= b'}
E Differing items:
E {'a': 'b'} != {'a': '= b'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
_____________________________ test_load[a-props17] _____________________________
data = 'a', props = {'a': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
_________________________ test_load[a \\u00ff-props27] _________________________
data = 'a \\\\u00ff', props = {'a': '\\u00ff'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': '\xff'} == {'a': '\\\\u00ff'}
E Differing items:
E {'a': '\xff'} != {'a': '\\\\u00ff'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
________________________ test_load[a \\\u00ff-props28] _________________________
data = 'a \\\\\\\\\\\\u00ff', props = {'a': '\\\xff'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': '\\u00ff'} == {'a': '\\\xff'}
E Differing items:
E {'a': '\\u00ff'} != {'a': '\\\xff'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
________________________ test_load[a \\\\u00ff-props29] ________________________
data = 'a \\\\\\\\u00ff', props = {'a': '\\\\u00ff'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': '\u00ff'} == {'a': '\\\\u00ff'}
E Differing items:
E {'a': '\u00ff'} != {'a': '\\\\u00ff'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
__________________________ test_load[a \\x7f-props31] __________________________
data = 'a \\\\x7f', props = {'a': '\\x7f'}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
> assert dict(p.items()) == props
E assert {'a': ''} == {'a': '\\x7f'}
E Differing items:
E {'a': ''} != {'a': '\\x7f'}
E Use -v to get the full diff
test_functional.py:93: AssertionError
__________________________ test_load[a
b
c
-props32] ___________________________
data = 'a\nb\nc\n', props = {'a': '', 'b': '', 'c': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
_________________________ test_load[a
b
c
-props33] _________________________
data = 'a\r\nb\r\nc\r\n', props = {'a': '', 'b': '', 'c': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
__________________________ test_load[a
b
c
-props34] ___________________________
data = 'a\rb\rc\r', props = {'a': '', 'b': '', 'c': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a\rb\rc'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a\rb\rc'
jproperties.py:154: SyntaxError
________________________ test_load[a
b
c
-props35] ________________________
data = 'a\nb\n \t \n\nc\n', props = {'a': '', 'b': '', 'c': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
_________________________ test_load[a
b\
c
d
-props36] _________________________
data = 'a\nb\\\nc\nd\n', props = {'a': '', 'bc': '', 'd': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
________________________ test_load[a
b \
c
d
-props37] _________________________
data = 'a\nb \\\nc\nd\n', props = {'a': '', 'b': 'c', 'd': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
________________________ test_load[a
b\
c
d
-props38] _________________________
data = 'a\nb\\\n c\nd\n', props = {'a': '', 'bc': '', 'd': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
________________________ test_load[a
b\\
c
d
-props39] _________________________
data = 'a\nb\\\\\nc\nd\n', props = {'a': '', 'b\\': '', 'c': '', 'd': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
________________________ test_load[a
b\\\
c
d
-props40] ________________________
data = 'a\nb\\\\\\\nc\nd\n', props = {'a': '', 'b\\c': '', 'd': ''}
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
> p.load(BytesIO(data))
test_functional.py:92:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
jproperties.py:205: in load
key, separator, value = self._separate(line)
jproperties.py:177: in _separate
key = getkey(line)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
s = 'a'
def getkey(s):
ret = []
escaping = False
for c in s:
if not escaping:
if c in " :=":
return "".join(ret)
elif c == "\\":
escaping = True
else:
escaping = False
ret.append(c)
> raise SyntaxError(repr(s))
E SyntaxError: 'a'
jproperties.py:154: SyntaxError
_________________________ test_store[props4-a = x \f] __________________________
props = {'a': 'x \x0c'}, data = 'a = x \\f'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = x \\x0c' == 'a = x \\f'
E - a = x \\x0c
E ? ^^^
E + a = x \\f
E ? ^
test_functional.py:145: AssertionError
__________________________ test_store[props8-a = \f] ___________________________
props = {'a': '\x0c'}, data = 'a = \\f'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x0c' == 'a = \\f'
E - a = \\x0c
E ? ^^^
E + a = \\f
E ? ^
test_functional.py:145: AssertionError
________________________ test_store[props10-a = \u0000] ________________________
props = {'a': '\x00'}, data = 'a = \\u0000'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x00' == 'a = \\u0000'
E - a = \\x00
E ? ^
E + a = \\u0000
E ? ^ ++
test_functional.py:145: AssertionError
________________________ test_store[props11-a = \u0000] ________________________
props = {'a': ''}, data = 'a = \\u0000'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x00' == 'a = \\u0000'
E - a = \\x00
E ? ^
E + a = \\u0000
E ? ^ ++
test_functional.py:145: AssertionError
________________________ test_store[props12-a = \u0019] ________________________
props = {'a': '\x19'}, data = 'a = \\u0019'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x19' == 'a = \\u0019'
E - a = \\x19
E ? ^
E + a = \\u0019
E ? ^^^
test_functional.py:145: AssertionError
________________________ test_store[props13-a = \u0019] ________________________
props = {'a': ''}, data = 'a = \\u0019'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x19' == 'a = \\u0019'
E - a = \\x19
E ? ^
E + a = \\u0019
E ? ^^^
test_functional.py:145: AssertionError
________________________ test_store[props14-a = \u007f] ________________________
props = {'a': '\x7f'}, data = 'a = \\u007f'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x7f' == 'a = \\u007f'
E - a = \\x7f
E ? ^
E + a = \\u007f
E ? ^^^
test_functional.py:145: AssertionError
________________________ test_store[props15-a = \u007f] ________________________
props = {'a': ''}, data = 'a = \\u007f'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = \\x7f' == 'a = \\u007f'
E - a = \\x7f
E ? ^
E + a = \\u007f
E ? ^^^
test_functional.py:145: AssertionError
______________________ test_store[props17-a = \ \ x\ty ] _______________________
props = {'a': ' x\ty '}, data = 'a = \\ \\ x\\ty '
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = x\\ty ' == 'a = \\ \\ x\\ty '
E - a = x\\ty
E ? ^
E + a = \\ \\ x\\ty
E ? ^^^^^
test_functional.py:145: AssertionError
__________________________ test_store[props21-a = \=] __________________________
props = {'a': '='}, data = 'a = \\='
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = =' == 'a = \\='
E - a = =
E + a = \\=
E ? ++
test_functional.py:145: AssertionError
__________________________ test_store[props22-a = \:] __________________________
props = {'a': ':'}, data = 'a = \\:'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = :' == 'a = \\:'
E - a = :
E + a = \\:
E ? ++
test_functional.py:145: AssertionError
__________________________ test_store[props23-a = \#] __________________________
props = {'a': '#'}, data = 'a = \\#'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = #' == 'a = \\#'
E - a = #
E + a = \\#
E ? ++
test_functional.py:145: AssertionError
__________________________ test_store[props24-a = \!] __________________________
props = {'a': '!'}, data = 'a = \\!'
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
> assert str(p) == data
E assert 'a = !' == 'a = \\!'
E - a = !
E + a = \\!
E ? ++
test_functional.py:145: AssertionError
===================== 33 failed, 33 passed in 0.24 seconds =====================
from io import BytesIO
import pytest
import jproperties
loading_tests = [
# Key value with equals
(b'a=b', {'a': 'b'}),
(b'a= b', {'a': 'b'}),
(b'a = b', {'a': 'b'}),
(b'a =b', {'a': 'b'}),
# Key value with colon
(b'a:b', {'a': 'b'}),
(b'a: b', {'a': 'b'}),
(b'a : b', {'a': 'b'}),
(b'a :b', {'a': 'b'}),
# Key terminator after terminator
(b'a : : b', {'a': ': b'}),
(b'a::b', {'a': ':b'}),
(b'a = = b', {'a': '= b'}),
(b'a==b', {'a': '=b'}),
(b'a = : b', {'a': ': b'}),
(b'a : = b', {'a': '= b'}),
# Key terminator escaped
(br'a\=b = c', {r'a=b': 'c'}),
(br'a\:b\=c : d', {r'a:b=c': 'd'}),
# Key value with space only
(b'a b', {'a': 'b'}),
# Key value empty value
(b'a', {'a': ''}),
# Escaping
# Basic backslash escapes
(b'a \\t', {'a': '\t'}),
(b'a \\n', {'a': '\n'}),
(b'a \\f', {'a': '\f'}),
(b'a \\r', {'a': '\r'}),
# Unrecognized escapes
(br'a \=', {'a': '='}),
(br'a \:', {'a': ':'}),
(br'a \b', {'a': 'b'}),
# Unicode escape
(br'a \u00ff', {'a': u'\u00ff'}),
# Unicode encoded backslash
(br'a \u005cb', {'a': u'\\b'}),
# Unicode with preceding escaped backslashes
(br'a \\u00ff', {'a': r'\u00ff'}),
(br'a \\\u00ff', {'a': u'\\\u00ff'}),
(br'a \\\\u00ff', {'a': r'\\u00ff'}),
# Latin-1 encoded bytes
(b'a \x7f', {'a': u'\x7f'}),
# Escaped backslash
(b'a \\\\x7f', {'a': '\\x7f'}),
# Line endings
# Simple
(b'a\nb\nc\n', {'a': '', 'b': '', 'c': ''}),
# Windows newlines
(b'a\r\nb\r\nc\r\n', {'a': '', 'b': '', 'c': ''}),
# Mac newlines
(b'a\rb\rc\r', {'a': '', 'b': '', 'c': ''}),
# Blank lines
(b'a\nb\n \t \n\nc\n', {'a': '', 'b': '', 'c': ''}),
# Line continuation
(b'a\nb\\\nc\nd\n', {'a': '', 'bc': '', 'd': ''}),
# Line continuation trailing blanks
(b'a\nb \\\nc\nd\n', {'a': '', 'b': 'c', 'd': ''}),
# Line continuation skips leading blanks
(b'a\nb\\\n c\nd\n', {'a': '', 'bc': '', 'd': ''}),
# Escaped backslash not continuation
(b'a\nb\\\\\nc\nd\n', {'a': '', 'b\\': '', 'c': '', 'd': ''}),
# Escaped backslash before continuation
(b'a\nb\\\\\\\nc\nd\n', {'a': '', 'b\\c': '', 'd': ''}),
]
@pytest.mark.parametrize('data,props', loading_tests)
def test_load(data, props):
p = jproperties.Properties()
p.load(BytesIO(data))
assert dict(p.items()) == props
storing_tests = [
# Simple
({'a': 'b'}, b'a = b'),
# Escaping basic
({'a': '\\'}, b'a = \\\\'),
({'a': 'x \t'}, br'a = x \t'),
({'a': 'x \n'}, br'a = x \n'),
({'a': 'x \f'}, br'a = x \f'),
({'a': 'x \r'}, br'a = x \r'),
# Escape whitespace-only value
({'a': '\t'}, br'a = \t'),
({'a': '\n'}, br'a = \n'),
({'a': '\f'}, br'a = \f'),
({'a': '\r'}, br'a = \r'),
# Escape unicode
({'a': '\x00'}, br'a = \u0000'),
({'a': u'\u0000'}, br'a = \u0000'),
({'a': '\x19'}, br'a = \u0019'),
({'a': u'\u0019'}, br'a = \u0019'),
({'a': '\x7f'}, br'a = \u007f'),
({'a': u'\u007f'}, br'a = \u007f'),
({'a': u'\uffff'}, br'a = \uffff'),
# Escape value leading whitespace
({'a': ' x\ty '}, br'a = \ \ x\ty '),
# Escape key terminators
({'=': ''}, br'\= = '),
({':': ''}, br'\: = '),
({' x ': ''}, br'\ x\ = '),
# Escape key terminators in value
({'a': '='}, br'a = \='),
({'a': ':'}, br'a = \:'),
# Escape comment markers
({'a': '#'}, br'a = \#'),
({'a': '!'}, br'a = \!'),
]
@pytest.mark.parametrize('props,data', storing_tests)
def test_store(props, data):
p = jproperties.Properties()
for key, value in props.iteritems():
p[key] = value
assert str(p) == data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment