diff --git a/soitool/database.py b/soitool/database.py index 98d509249accd9e5eac12bfa7c68b79b8d182299..fc2289c2add8cf185c9e31817938319015bad7e8 100644 --- a/soitool/database.py +++ b/soitool/database.py @@ -36,6 +36,8 @@ class Database(): else: print('Creating new DB.') self.conn = sqlite3.connect(DBPATH) + # self.conn.cursor().execute('pragma encoding=UTF8') + self.create_tables() print('DB created.') self.fill_tables() @@ -62,10 +64,11 @@ class Database(): def fill_codebook(self): """Read data from codebook.json and fills DB-table CodeBook.""" file_path = os.path.join(CURDIR, "testdata/codebook.json") + # Load json as dict - with open(file_path, "r") as file: - codewords = json.load(file) - file.close() + f = open(file_path, "r", encoding="utf-8") + codewords = json.load(f) + f.close() # Insert data in db stmt = 'INSERT INTO CodeBook(Word, Category, Type, Code)' \ diff --git a/test/test_database.py b/test/test_database.py index 38c82788c5b38e800fe493d32f9fcae9a252a9fb..cf3ab2e8f3c20ebff822929b891677eafa9cc95a 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -83,9 +83,9 @@ class DatabaseTest(unittest.TestCase): """Assert function get_codebook works as expected.""" # Get test-data from json file_path = os.path.join(TESTDATA_PATH, "codebook.json") - with open(file_path, "r") as file: - expected = json.load(file) - file.close() + f = open(file_path, "r", encoding="utf-8") + expected = json.load(f) + f.close() # Get data from db stmt = 'SELECT * FROM CodeBook' @@ -126,9 +126,9 @@ class DatabaseTest(unittest.TestCase): """Assert function get_codebook returns full codebook.""" # Load full codebook file_path = os.path.join(TESTDATA_PATH, "codebook.json") - with open(file_path, "r") as file: - expected = json.load(file) - file.close() + f = open(file_path, "r", encoding="utf-8") + expected = json.load(f) + f.close() # Get full codebook from db actual = self.database.get_codebook() @@ -147,9 +147,9 @@ class DatabaseTest(unittest.TestCase): """Assert function get_codebook only return the small codebook.""" # Load full codebook file_path = os.path.join(TESTDATA_PATH, "codebook.json") - with open(file_path, "r") as file: - data = json.load(file) - file.close() + f = open(file_path, "r", encoding="utf-8") + data = json.load(f) + f.close() # Fill expected with only small codebook entries expected = []