Skip to content

Commit

Permalink
Include unit-test for read-only access
Browse files Browse the repository at this point in the history
Opening a SqliteDict in read-only mode should not
create a new table, only raise RuntimeError.
  • Loading branch information
hholst80 committed Jan 8, 2021
1 parent 474015a commit f118fae
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ def attempt_terminate():
with self.assertRaises(RuntimeError):
func()

def test_readonly_table(self):
"""
Read-only access on a non-existant tablename should raise RuntimeError,
and not create a new (empty) table.
"""
fname = norm_file('tests/db/sqlitedict-override-test.sqlite')
dummy_tablename = 'table404'
orig_db = SqliteDict(filename=fname)
orig_db['key'] = 'value'
orig_db['key_two'] = 2
orig_db.commit()
orig_db.close()

self.assertFalse(dummy_tablename in SqliteDict.get_tablenames(fname))

with self.assertRaises(RuntimeError):
SqliteDict(filename=fname, tablename=dummy_tablename, flag='r')

self.assertFalse(dummy_tablename in SqliteDict.get_tablenames(fname))

def test_irregular_tablenames(self):
"""Irregular table names need to be quoted"""
def __test_irregular_tablenames(tablename):
Expand Down

0 comments on commit f118fae

Please sign in to comment.