Skip to content
Snippets Groups Projects
Commit 4ae3da51 authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

#42 Endret innlesing av kodebok-data til utf-8

parent 7e1b2911
No related branches found
No related tags found
1 merge request!31#42 og #43 Kodebok-GUI
......@@ -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)' \
......
......@@ -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 = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment