r"""Open a database only for reading
(tmpdir)
| 80 | |
| 81 | |
| 82 | def test_json_read(tmpdir): |
| 83 | r"""Open a database only for reading""" |
| 84 | path = str(tmpdir.join('test.db')) |
| 85 | with pytest.raises(FileNotFoundError): |
| 86 | db = TinyDB(path, storage=JSONStorage, access_mode='r') |
| 87 | # Create small database |
| 88 | db = TinyDB(path, storage=JSONStorage) |
| 89 | db.insert({'b': 1}) |
| 90 | db.insert({'a': 1}) |
| 91 | db.close() |
| 92 | # Access in read mode |
| 93 | db = TinyDB(path, storage=JSONStorage, access_mode='r') |
| 94 | assert db.get(where('a') == 1) == {'a': 1} # reading is fine |
| 95 | with pytest.raises(IOError): |
| 96 | db.insert({'c': 1}) # writing is not |
| 97 | db.close() |
| 98 | |
| 99 | |
| 100 | def test_create_dirs(): |