tests.unit.test_util   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 117
rs 9.6
c 0
b 0
f 0
wmc 35

15 Functions

Rating   Name   Duplication   Size   Complexity  
A test_wrap_bad_n_type_float() 0 4 2
A test_wrap_bad_m_type_float() 0 4 2
A test_wrap_bad_m_negative() 0 4 2
A test_wrap_bad_m_type_str() 0 4 2
A test_load_dataset_bad_dataset_missing() 0 4 2
A test_load_dataset_bad_root_missing() 0 4 2
A test_wrap_bad_n_zero() 0 4 2
A test_load_dataset_correctness() 0 4 3
A test_wrap_bad_para_type_float() 0 4 2
A test_wrap_bad_n_type_str() 0 4 2
A test_load_dataset_bad_root_type_float() 0 5 2
B test_wrap_correctness() 0 11 6
A test_load_dataset_bad_data_type() 0 6 2
A test_load_dataset_bad_dataset_type_float() 0 5 2
A test_load_dataset_bad_separator_type_float() 0 6 2
1
"""
2
:mod:`tests.unit.test_util` -- Unit Tests
3
=========================================
4
5
.. module:: tests.unit.test_util
6
   :synopsis: Unit tests for the lib.util module.
7
8
.. moduleauthor:: Bill Maroney <[email protected]>
9
"""
10
11
import pytest
12
13
from lib.util import wrap, load_dataset
14
15
16
def test_wrap_correctness():
17
    """ Test the correctness of :func:`lib.util.wrap` by examining outputs for expected properties """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
18
    long_line = "I'm a long line, but how long, really, is a line?"
19
    long_para = 400 * long_line
20
    m, n = 4, 120
0 ignored issues
show
Coding Style Naming introduced by
The name m 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...
Coding Style Naming introduced by
The name n 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
    wrapped_para = wrap(long_para, m, n)
22
    assert isinstance(wrapped_para, str), "wrong type"
23
    for line in wrapped_para.split("\n"):
24
        assert isinstance(line, str), "wrong type"
25
        assert line.startswith(m * " "), "incorrect white-space padding at front of line"
26
        assert len(line) <= n, "line is too long"
27
28
29
def test_wrap_bad_para_type_float():
30
    """ Test that :func:`lib.util.wrap` raises a ``TypeError`` for a non-``int`` value for `para` (``float``) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

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

Loading history...
31
    with pytest.raises(TypeError):
32
        wrap(3.14, 4, 80)
33
34
35
def test_wrap_bad_m_type_str():
36
    """ Test that :func:`lib.util.wrap` raises a ``TypeError`` for a non-``int`` value for `m` (``str``) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

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

Loading history...
37
    with pytest.raises(TypeError):
38
        wrap("paragraph I be...", "bad", 80)
39
40
41
def test_wrap_bad_m_type_float():
42
    """ Test that :func:`lib.util.wrap` raises a ``TypeError`` for a non-``int`` value for `m` (``float``) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
43
    with pytest.raises(TypeError):
44
        wrap("paragraph I be...", 3.14, 80)
45
46
47
def test_wrap_bad_m_negative():
48
    """ Test that :func:`lib.util.wrap` raises a ``ValueError`` for a :math:`m \\lt 0` """
49
    with pytest.raises(ValueError):
50
        wrap("paragraph I be...", -14, 80)
51
52
53
def test_wrap_bad_n_type_str():
54
    """ Test that :func:`lib.util.wrap` raises a ``TypeError`` for a non-``int`` value for `n` (``str``) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

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

Loading history...
55
    with pytest.raises(TypeError):
56
        wrap("paragraph I be...", 4, "bad")
57
58
59
def test_wrap_bad_n_type_float():
60
    """ Test that :func:`lib.util.wrap` raises a ``TypeError`` for a non-``int`` value for `n` (``float``) """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
61
    with pytest.raises(TypeError):
62
        wrap("paragraph I be...", 4, 3.14)
63
64
65
def test_wrap_bad_n_zero():
66
    """ Test that :func:`lib.util.wrap` raises a ``ValueError`` for :math:`n = 0` """
67
    with pytest.raises(ValueError):
68
        wrap("paragraph I be...", 4, 0)
69
70
71
def test_load_dataset_correctness():
72
    """ Test the correctness of :func:`lib.util.load_dataset` by examining datatypes of outputs """
73
    for elt in load_dataset("general", "primes", data_type=int):
74
        assert isinstance(elt, int), "wrong type"
75
76
77
def test_load_dataset_bad_root_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_load_dataset_bad_root_type_float 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...
78
    """ Test that :func:`lib.util.load_dataset` raises a ``TypeError`` for a non-``str`` value for `root` (``float``)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

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

Loading history...
79
    """
80
    with pytest.raises(TypeError):
81
        load_dataset(3.14, "primes")
82
83
84
def test_load_dataset_bad_root_missing():
0 ignored issues
show
Coding Style Naming introduced by
The name test_load_dataset_bad_root_missing 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...
85
    """ Test that :func:`lib.util.load_dataset` raises a ``FileNotFoundError`` for a non-existent directory `root` """
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

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

Loading history...
86
    with pytest.raises(FileNotFoundError):
87
        load_dataset("i_dont_exist", "primes")
88
89
90
def test_load_dataset_bad_dataset_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_load_dataset_bad_dataset_type_float 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...
91
    """ Test that :func:`lib.util.load_dataset` raises a ``TypeError`` for a non-``str`` value for `dataset` (``float``)
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...
92
    """
93
    with pytest.raises(TypeError):
94
        load_dataset("general", 3.14)
95
96
97
def test_load_dataset_bad_dataset_missing():
0 ignored issues
show
Coding Style Naming introduced by
The name test_load_dataset_bad_dataset_missing 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...
98
    """ Test that :func:`lib.util.load_dataset` raises a ``FileNotFoundError`` for a non-existent file `dataset` """
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...
99
    with pytest.raises(FileNotFoundError):
100
        load_dataset("general", "3.14")
101
102
103
def test_load_dataset_bad_separator_type_float():
0 ignored issues
show
Coding Style Naming introduced by
The name test_load_dataset_bad_separator_type_float 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...
104
    """ Test that :func:`lib.util.load_dataset` raises a ``TypeError`` for a non-``str`` value for `separator`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
105
        (``float``)
106
    """
107
    with pytest.raises(TypeError):
108
        load_dataset("general", "primes", separator=12.34)
109
110
111
def test_load_dataset_bad_data_type():
112
    """ Test that :func:`lib.util.load_dataset` raises a ``TypeError`` for a non-``type`` value for `data_type`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

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

Loading history...
113
        (``int``)
114
    """
115
    with pytest.raises(TypeError):
116
        load_dataset("general", "primes", data_type=7)
117