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

#5 Tilpasset docstrings

parent efc1b807
No related branches found
No related tags found
1 merge request!10Database setup
Pipeline #71706 passed
"""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.
Retrieve the entries belonging to the full or small codebook.
Parameters
----------
small : Bool
Full or smal codebook to be returned
Full or small codebook to be returned
Returns
-------
codebook : list (of dicts)
[{'word': str, 'type': str, 'category': str, 'code': str}]
"""
# Get either small or whole codebook
# Get either full or small codebook
stmt = 'SELECT * FROM CodeBook'
if small:
stmt = stmt + ' WHERE Type = ?'
......
......@@ -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")
......
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