Example #1
0
 def test_iter(self, tmpfile):
     f = File(tmpfile, 'w')
     f.write_array('c', 10)
     f.write_array('a', [1, 2, 3])
     f.write_json('b', {'foo': 'bar'})
     f.write_json('d', 42)
     assert list(f) == ['a', 'b', 'c', 'd']
     f.close()
     f = File(tmpfile)
     assert list(f) == ['a', 'b', 'c', 'd']
Example #2
0
 def test_invalid_key(self, tmpfile):
     f = File(tmpfile, 'w')
     pytest.raises_regexp(ValueError, 'invalid key: expected string',
                          f.write_json, 42, 0)
     pytest.raises_regexp(ValueError, 'invalid key: empty string',
                          f.write_json, '', 0)
     f.write_json('foo', 'bar')
     pytest.raises_regexp(ValueError, "key already exists: 'foo'",
                          f.write_json, 'foo', 'baz')
     f.close()
     f = File(tmpfile)
     pytest.raises_regexp(ValueError, 'invalid key: expected string',
                          f.read, 42)
     pytest.raises_regexp(KeyError, 'bar',
                          f.read, 'bar')