Passed
Push — master ( 9e6838...cf264a )
by Yang
27s
created

test_LocalDBCreate_CNBP()   B

Complexity

Conditions 6

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 33
rs 8.6166
c 0
b 0
f 0
cc 6
nop 0
1
from pathlib import Path
0 ignored issues
show
Coding Style Naming introduced by
The name test_LocalDBCreate does not conform to the module naming conventions ((([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import logging
3
import os
4
import sys
5
from LocalDB.create_CNBP import LocalDBCreate, create_localDB_CNBP
0 ignored issues
show
Bug introduced by
The name create_CNBP does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.create_CNBP'
Loading history...
6
from LocalDB.query import check_header
0 ignored issues
show
Bug introduced by
The name query does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.query'
Loading history...
7
from LocalDB.schema import CNBP_schema_table_name, CNBP_schema, CNBP_schema_types
0 ignored issues
show
Bug introduced by
The name schema does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.schema'
Loading history...
8
9
10
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
11
12
def test_LocalDBCreate():
0 ignored issues
show
Coding Style Naming introduced by
The name test_LocalDBCreate does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
13
    logger = logging.getLogger('UT_LocalDBCreate')
14
    PathString = "Test.sqlite"
0 ignored issues
show
Coding Style Naming introduced by
The name PathString does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
15
    # if SQL already exist, quit script.
16
    SQLPath = Path(PathString)
0 ignored issues
show
Coding Style Naming introduced by
The name SQLPath does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
17
18
    # check if path is a fiel and exist.
19
    if SQLPath.is_file():
20
        logger.info('Test SQLite database file already exist. Gonna mess with it!')
21
        ''''Delete current database! During testing only'''
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...
22
        os.remove(PathString)
23
24
    table_name = 'whatchacallitid_table'  # All CNBP database should have this table name.
25
    KeyFieldString = 'whatchacalitkeyfield'
0 ignored issues
show
Coding Style Naming introduced by
The name KeyFieldString does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
26
27
    # must pappend DBKEY creaed as the indexer column.
28
    NewColumns = ['whasdfasdfasdffsdf', '123345sdb', 'CNvaasa31NID', 'CNFUasdfNID', 'Ha1234sh1', 'Hasha2', 'adsfas']
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name NewColumns does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
29
    NewColumnsTypes = ['TEXT', 'BLOB', 'REAL', 'TEXT', 'TEXT', 'BLOB', 'TEXT']
0 ignored issues
show
Coding Style Naming introduced by
The name NewColumnsTypes does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
30
31
    NewColumnSpec = zip(NewColumns, NewColumnsTypes)
0 ignored issues
show
Coding Style Naming introduced by
The name NewColumnSpec does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
32
    NewColumnSpecList = list(NewColumnSpec)
0 ignored issues
show
Coding Style Naming introduced by
The name NewColumnSpecList does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
33
34
    # Create the database
35
    assert LocalDBCreate(PathString, table_name, KeyFieldString, NewColumnSpecList)
36
37
38
39
    table_header = check_header(PathString, table_name)
40
41
    # Remove database before assertion that potentially fail.
42
    os.remove(PathString)
43
44
    NewColumns = [KeyFieldString, 'whasdfasdfasdffsdf', '123345sdb', 'CNvaasa31NID', 'CNFUasdfNID', 'Ha1234sh1',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (112/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name NewColumns does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
45
                  'Hasha2', 'adsfas']
46
    NewColumnsTypes = ['INTEGER', 'TEXT', 'BLOB', 'REAL', 'TEXT', 'TEXT', 'BLOB', 'TEXT']
0 ignored issues
show
Coding Style Naming introduced by
The name NewColumnsTypes does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
47
48
    for index in range(0, len(NewColumns)):
49
        print(table_header[index][1])
50
        assert table_header[index][1] == NewColumns[index]
51
        print(table_header[index][2])
52
        assert table_header[index][2] == NewColumnsTypes[index]
53
54
    return True
55
56
def test_LocalDBCreate_CNBP():
0 ignored issues
show
Coding Style Naming introduced by
The name test_LocalDBCreate_CNBP does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
57
    logger = logging.getLogger('UT_LocalDBCreate_CNBP')
58
    PathString = "TestCNBP.sqlite"
0 ignored issues
show
Coding Style Naming introduced by
The name PathString does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
59
    # if SQL already exist, quit script.
60
    SQLPath = Path(PathString)
0 ignored issues
show
Coding Style Naming introduced by
The name SQLPath does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
61
62
    # check if path is a fiela nd exist.
63
    if SQLPath.is_file():
64
        logger.info('Test SQLite database file already exist. Gonna mess with it!')
65
        ''''Delete current database! During testing only'''
0 ignored issues
show
Unused Code introduced by
This string statement has no effect and could be removed.
Loading history...
66
        os.remove(PathString)
67
68
    # Create the database
69
    assert create_localDB_CNBP(PathString)
70
71
72
    tableName = CNBP_schema_table_name #All CNBP database should have this table name.
0 ignored issues
show
Coding Style Naming introduced by
The name tableName does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
73
74
    fetchallResult = check_header(PathString, tableName)
0 ignored issues
show
Coding Style Naming introduced by
The name fetchallResult does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
75
76
    # remove test database
77
    os.remove(PathString)
78
79
    # must pappend DBKEY creaed as the indexer column.
80
81
    for index in range(0, len(CNBP_schema)):
82
        print(fetchallResult[index][1])
83
        assert fetchallResult[index][1] == CNBP_schema[index]
84
        print(fetchallResult[index][2])
85
        assert fetchallResult[index][2] == CNBP_schema_types[index]
86
87
88
    return True
89
90
if __name__ == '__main__':
91
    test_LocalDBCreate()
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...