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
1f300e34
Commit
1f300e34
authored
5 years ago
by
Anders H. Rebner
Browse files
Options
Downloads
Patches
Plain Diff
#5 Tilpasset docstrings
parent
efc1b807
No related branches found
Branches containing commit
No related tags found
1 merge request
!10
Database setup
Pipeline
#71706
passed
5 years ago
Stage: lint
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
soitool/database.py
+10
-6
10 additions, 6 deletions
soitool/database.py
test/test_database.py
+2
-8
2 additions, 8 deletions
test/test_database.py
with
12 additions
and
14 deletions
soitool/database.py
+
10
−
6
View file @
1f300e34
"""
Database
.
"""
"""
Includes all database-related functionality
.
"""
import
os
import
sqlite3
import
json
...
...
@@ -18,10 +18,14 @@ BYHEART = 'CREATE TABLE ByHeart(Word VARCHAR PRIMARY KEY)'
class
Database
():
"""
Holds connection to database.
"""
"""
Holds database-connection and related functions.
Connects to existing db if found, creates new db if not.
If db is created, tables are created and filled.
"""
def
__init__
(
self
):
"""
Connect to existing db if found, create new db if not.
"""
db_exists
=
os
.
path
.
exists
(
DBPATH
)
if
db_exists
:
...
...
@@ -122,19 +126,19 @@ class Database():
def
get_codebook
(
self
,
small
=
False
):
"""
Retrive the entries belonging to the
small codebook or big
codebook.
Retri
e
ve the entries belonging to the
full or small
codebook.
Parameters
----------
small : Bool
Full or smal codebook to be returned
Full or smal
l
codebook to be returned
Returns
-------
codebook : list (of dicts)
[{
'
word
'
: str,
'
type
'
: str,
'
category
'
: str,
'
code
'
: str}]
"""
# Get either
sma
ll or
whole
codebook
# Get either
fu
ll or
small
codebook
stmt
=
'
SELECT * FROM CodeBook
'
if
small
:
stmt
=
stmt
+
'
WHERE Type = ?
'
...
...
This diff is collapsed.
Click to expand it.
test/test_database.py
+
2
−
8
View file @
1f300e34
...
...
@@ -9,13 +9,7 @@ TESTDATA_PATH = Path(__file__).parent.parent / "soitool/testdata"
class
DatabaseTest
(
unittest
.
TestCase
):
"""
Database tests.
Parameters
----------
unittest : Testcase
DatabaseTest is subclass of TestCase
"""
"""
Database tests.
"""
def
setUp
(
self
):
"""
Connect to/create database.
"""
...
...
@@ -128,7 +122,7 @@ class DatabaseTest(unittest.TestCase):
categories_db
=
self
.
database
.
get_categories
()
self
.
assertEqual
(
categories_file
,
categories_db
)
def
test_getcodebook
(
self
):
def
test_get
_
codebook
(
self
):
"""
Assert function get_codebook returns full codebook.
"""
# Load full codebook
file_path
=
os
.
path
.
join
(
TESTDATA_PATH
,
"
codebook.json
"
)
...
...
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