Passed
Pull Request — master (#3)
by Yang
04:58
created

Python.LocalDB.test_LocalDBCreate   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 58
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A UT_LocalDBCreate.test_LocalDBCreate() 0 42 3
A UT_LocalDBCreate.test_LocalDBCreate_CNBP() 0 32 3
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
import unittest
6
from LocalDB.create_CNBP import LocalDB_createCNBP
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...
7
from LocalDB.create import LocalDB_create
0 ignored issues
show
Bug introduced by
The name create does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.create'
Loading history...
8
from LocalDB.query import LocalDB_query
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...
9
from LocalDB.schema import CNBP_blueprint
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...
10
11
12
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
13
14
15
class UT_LocalDBCreate(unittest.TestCase):
0 ignored issues
show
Coding Style Naming introduced by
The name UT_LocalDBCreate does not conform to the class naming conventions ([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 class 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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
16
17
    @staticmethod
18
    def test_LocalDBCreate():
0 ignored issues
show
Coding Style Naming introduced by
The name test_LocalDBCreate does not conform to the method 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 method 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...
19
        logger = logging.getLogger('UT_LocalDBCreate')
20
        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...
21
        # if SQL already exist, quit script.
22
        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...
23
24
        # check if path is a fiel and exist.
25
        if SQLPath.is_file():
26
            logger.info('Test SQLite database file already exist. Gonna mess with it!')
27
            ''''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...
28
            os.remove(PathString)
29
30
        table_name = 'whatchacallitid_table'  # All CNBP database should have this table name.
31
        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...
32
33
        # must pappend DBKEY creaed as the indexer column.
34
        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 (120/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...
35
        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...
36
37
        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...
38
        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...
39
40
        # Create the database
41
        assert LocalDB_create.database(PathString, table_name, KeyFieldString, NewColumnSpecList)
42
43
        table_header = LocalDB_query.check_header(PathString, table_name)
44
45
        # Remove database before assertion that potentially fail.
46
        os.remove(PathString)
47
48
        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 (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...
49
                      'Hasha2', 'adsfas']
50
        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...
51
52
        for index in range(0, len(NewColumns)):
53
            print(table_header[index][1])
54
            assert table_header[index][1] == NewColumns[index]
55
            print(table_header[index][2])
56
            assert table_header[index][2] == NewColumnsTypes[index]
57
58
        return True
59
60
    @staticmethod
61
    def test_LocalDBCreate_CNBP():
0 ignored issues
show
Coding Style Naming introduced by
The name test_LocalDBCreate_CNBP does not conform to the method 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 method 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...
62
        logger = logging.getLogger('UT_LocalDBCreate_CNBP')
63
        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...
64
        # if SQL already exist, quit script.
65
        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...
66
67
        # check if path is a fiela nd exist.
68
        if SQLPath.is_file():
69
            logger.info('Test SQLite database file already exist. Gonna mess with it!')
70
            ''''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...
71
            os.remove(PathString)
72
73
        # Create the database
74
        assert LocalDB_createCNBP.database(PathString)
75
76
77
        tableName = CNBP_blueprint.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...
78
79
        fetchallResult = LocalDB_query.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...
80
81
        # remove test database
82
        os.remove(PathString)
83
84
        # must pappend DBKEY creaed as the indexer column.
85
86
        for index in range(0, len(CNBP_blueprint.schema)):
87
            print(fetchallResult[index][1])
88
            assert fetchallResult[index][1] == CNBP_blueprint.schema[index]
89
            print(fetchallResult[index][2])
90
            assert fetchallResult[index][2] == CNBP_blueprint.schema_types[index]
91
        return True
92
93
if __name__ == '__main__':
94
    UT_LocalDBCreate.test_LocalDBCreate()
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...