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
37101eaf
Commit
37101eaf
authored
5 years ago
by
Anders H. Rebner
Browse files
Options
Downloads
Patches
Plain Diff
#57 Database tar imot db_path
parent
657a3233
No related branches found
Branches containing commit
No related tags found
2 merge requests
!44
#57 Database: testmodus og bruk samme instans overalt
,
!42
WIP: #57 Én databaseinstans og testmodus for database
Pipeline
#76596
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
+2
-11
2 additions, 11 deletions
soitool/database.py
test/test_database.py
+6
-2
6 additions, 2 deletions
test/test_database.py
with
8 additions
and
13 deletions
soitool/database.py
+
2
−
11
View file @
37101eaf
...
...
@@ -8,10 +8,8 @@ from soitool.enumerates import CodebookSort
# Set name and path to (future) database
DBNAME
=
"
database
"
TESTDBNAME
=
"
testDatabase
"
CURDIR
=
os
.
path
.
dirname
(
__file__
)
DBPATH
=
os
.
path
.
join
(
CURDIR
,
DBNAME
)
TESTDBPATH
=
os
.
path
.
join
(
CURDIR
,
TESTDBNAME
)
# Number og seconds in 24h
SECONDS_IN_24H
=
24
*
60
*
60
...
...
@@ -40,16 +38,9 @@ class Database:
If db is created, tables are created and filled.
Holds a QTimer that requests an update of CodeBook on every timeout.
Database can be run in testmode, this will create a seperate database-file.
"""
def
__init__
(
self
,
testmode
=
False
):
if
testmode
:
db_path
=
TESTDBPATH
else
:
db_path
=
DBPATH
def
__init__
(
self
,
db_path
=
DBPATH
):
db_exists
=
os
.
path
.
exists
(
db_path
)
...
...
@@ -67,7 +58,7 @@ class Database:
self
.
fill_tables
()
print
(
"
Tables filled with data.
"
)
self
.
conn
.
row_factory
=
sqlite3
.
Row
# Enables row[
'
columnName
'
]
self
.
conn
.
row_factory
=
sqlite3
.
Row
# Enables row[
"
columnName
"
]
def
create_tables
(
self
):
"""
Create tables CodeBook, CategoryWords and ByHeart.
"""
...
...
This diff is collapsed.
Click to expand it.
test/test_database.py
+
6
−
2
View file @
37101eaf
...
...
@@ -5,9 +5,13 @@ import unittest
import
json
from
time
import
sleep
from
datetime
import
datetime
from
soitool.database
import
Database
,
TESTDBPATH
from
soitool.database
import
Database
from
soitool.coder
import
get_code_length_needed
TESTDBNAME
=
"
testDatabase
"
SOITOOL_DIR
=
Path
(
__file__
).
parent
.
parent
/
"
soitool
"
TESTDBPATH
=
os
.
path
.
join
(
SOITOOL_DIR
,
TESTDBNAME
)
TESTDATA_PATH
=
Path
(
__file__
).
parent
.
parent
/
"
soitool/testdata
"
...
...
@@ -16,7 +20,7 @@ class DatabaseTest(unittest.TestCase):
def
setUp
(
self
):
"""
Connect to/create database.
"""
self
.
database
=
Database
(
testmode
=
True
)
self
.
database
=
Database
(
db_path
=
TESTDBPATH
)
self
.
addCleanup
(
self
.
delete_db
)
def
test_connection
(
self
):
...
...
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