Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
4ae3da51
Commit
4ae3da51
authored
5 years ago
by
Anders H. Rebner
Browse files
Options
Downloads
Patches
Plain Diff
#42 Endret innlesing av kodebok-data til utf-8
parent
7e1b2911
No related branches found
Branches containing commit
No related tags found
1 merge request
!31
#42 og #43 Kodebok-GUI
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
soitool/database.py
+6
-3
6 additions, 3 deletions
soitool/database.py
test/test_database.py
+9
-9
9 additions, 9 deletions
test/test_database.py
with
15 additions
and
12 deletions
soitool/database.py
+
6
−
3
View file @
4ae3da51
...
...
@@ -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
(
f
ile
)
f
ile
.
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)
'
\
...
...
This diff is collapsed.
Click to expand it.
test/test_database.py
+
9
−
9
View file @
4ae3da51
...
...
@@ -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
(
f
ile
)
f
ile
.
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
(
f
ile
)
f
ile
.
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
(
f
ile
)
f
ile
.
close
()
f
=
open
(
file_path
,
"
r
"
,
encoding
=
"
utf-8
"
)
data
=
json
.
load
(
f
)
f
.
close
()
# Fill expected with only small codebook entries
expected
=
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment