Passed
Push — main ( c9ac86...a4501a )
by Douglas
02:00
created

TestUnitTools.test_approx_time_wrt()   A

Complexity

Conditions 1

Size

Total Lines 32
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 29
nop 1
dl 0
loc 32
rs 9.184
c 0
b 0
f 0
1
from datetime import datetime
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
4
5
from pocketutils.core.chars import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like pocketutils.core.chars should generally be avoided.
Loading history...
Unused Code introduced by
Any was imported with wildcard, but is not used.
Loading history...
6
from pocketutils.tools.unit_tools import *
0 ignored issues
show
Unused Code introduced by
Tuple was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
StringTools was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
BaseTools was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
StringPatternError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OutOfRangeError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
nicesize was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PintTypeError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
UnitRegistry was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Quantity was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Union was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
SupportsFloat was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Optional was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
logger was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
regex was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
math was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
logging was imported with wildcard, but is not used.
Loading history...
Coding Style introduced by
The usage of wildcard imports like pocketutils.tools.unit_tools should generally be avoided.
Loading history...
Unused Code introduced by
timedelta was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
date was imported with wildcard, but is not used.
Loading history...
7
8
raises = pytest.raises
9
10
11
class TestUnitTools:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
12
    def test_delta_time_to_str(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
13
        f = UnitTools.delta_time_to_str
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
14
        assert f(15) == "15s"
15
        assert f(313) == "5.22min"
16
        assert f(15, space=Chars.narrownbsp) == "15" + Chars.narrownbsp + "s"
17
        assert f(15 * 60) == "15min"
18
        assert f(15 * 60 + 5) == "15.08min"
19
        assert f(15 * 60 * 60 + 5 * 60) == "15.08hr"
20
21
    def test_approx_time_wrt(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
22
        f = UnitTools.approx_time_wrt
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 2)) == "2021-01-02 00:00"
24
        assert f(datetime(2021, 1, 1), datetime(1996, 1, 1)) == "1996"
25
        assert f(datetime(2021, 1, 1), datetime(2021, 5, 5)) == "2021-05"
26
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 5)) == "2021-01-05"
27
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 1, 6)) == "2021-01-01 06:00"
28
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 1, 6, 22)) == "2021-01-01 06:22"
29
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 2, 6, 22)) == "2021-01-02 06:22"
30
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 2, 2, 22)) == "2021-01-02 02:22"
31
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 2, 2, 22, 40)) == "2021-01-02 02:22"
32
        assert f(datetime(2021, 1, 1), datetime(2021, 1, 1, 0, 1, 40)) == "2021-01-01 00:01:40"
33
        assert (
34
            f(datetime(2021, 1, 1), datetime(2021, 1, 1, 0, 0, 0, 222222))
35
            == "2021-01-01 00:00:00.222"
36
        )
37
        assert (
38
            f(datetime(2021, 1, 1), datetime(2021, 1, 1, 0, 0, 0, 222))
39
            == "2021-01-01 00:00:00.000222"
40
        )
41
        assert (
42
            f(datetime(2021, 1, 1), datetime(2021, 1, 1, 0, 0, 0, 0))
43
            == "2021-01-01 00:00:00.000000"
44
        )
45
        assert f(datetime(2021, 1, 10), datetime(2021, 1, 5)) == "2021-01-05"  # negative delta
46
        assert f(datetime(2021, 9, 30, 23), datetime(2021, 10, 1)) == "2021-10-01 00:00"
47
        assert f(datetime(2021, 10, 1), datetime(2021, 9, 30, 23)) == "2021-09-30 23:00"
48
        assert f(datetime(2021, 9, 27, 1), datetime(2021, 10, 1)) == "2021-10-01"
49
        assert f(datetime(2021, 10, 1), datetime(2021, 9, 25)) == "2021-09-25"
50
        assert (
51
            f(datetime(2021, 1, 1), datetime(2021, 1, 1, 0, 0, 0, 0), skip_today=True)
52
            == "00:00:00.000000"
53
        )
54
55
    def test_ms_to_minsec(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
introduced by
Missing function or method docstring
Loading history...
56
        f = UnitTools.ms_to_minsec
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
57
        assert f(15) == "15ms"
58
        assert f(15 * 1000) == "00:15"
59
        assert f(15 * 60 * 1000) == "15:00"
60
        assert f(15 * 60 * 60 * 1000) == "15:00:00"
61
        assert f(15 * 24 * 60 * 60 * 1000) == "15d:00:00:00"
62
63
    def test_round_to_sigfigs(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
64
        f = UnitTools.round_to_sigfigs
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
65
        assert str(f(0.0012, 3)) == "0.0012"
66
        assert str(f(0.0012, 1)) == "0.001"
67
        assert str(f(0.0012 / 1000 / 1000, 3)) == "1.2e-09"
68
        assert str(f(0.0012 / 1000 / 1000, 1)) == "1e-09"
69
70
    def test_format_micromolar(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
71
        f = UnitTools.format_micromolar
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
72
        assert f(1.2) == "1.2µM"
73
        assert f(1.2, space=Chars.narrownbsp) == "1.2" + Chars.narrownbsp + "µM"
74
        assert f(0.0012) == "1.2nM"
75
        assert f(0.0012 / 1000) == "1.2pM"
76
        assert f(0.0012 / 1e6) == "1.2fM"
77
        assert f(9999) == "9.999mM"
78
        assert f(1000 * 1000) == "1M"
79
        assert f(9999999) == "10M"
80
81
    def test_dose_to_micromolar(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
82
        f = UnitTools.concentration_to_micromolar
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
83
        assert f(55, "M") == 55 * 1e6
84
        assert f(55, "mM") == 55 * 1e3
85
        assert f(55, "uM") == 55
86
        assert f(-55, "uM") == -55
87
        assert f(55, "µM") == 55
88
        assert f(55, "nM") * 1e3 == 55
89
        assert f(-55, "nM") * 1e3 == -55
90
        assert pytest.approx(f(-55, "nM") * 1e3, -55)
91
        assert pytest.approx(f(55, "pM") * 1e6, 55)
92
        assert pytest.approx(f(55, "fM") * 1e9, 55)
93
94
    def test_extract_dose(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
introduced by
Missing function or method docstring
Loading history...
95
        f = UnitTools.extract_micromolar
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
96
        assert f("abc 55 nM") == 55 / 1000
97
        assert f("abc 55{}uM".format(Chars.narrownbsp)) == 55
98
        assert f("abc 55 uM") == 55
99
        assert f("a.55bc 55uM") == 55
100
101
    def test_split_drug_dose(self):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
introduced by
Missing function or method docstring
Loading history...
102
        f = UnitTools.split_species_micromolar
0 ignored issues
show
Coding Style Naming introduced by
Variable name "f" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

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...
103
        assert f("abc 55 nM") == ("abc", 55 / 1000)
104
        assert f("abc 55{}uM".format(Chars.narrownbsp)) == ("abc", 55)
105
        assert f("abc 55 uM") == ("abc", 55)
106
        assert f("a.55bc 55uM") == ("a.55bc", 55)
107
        assert f("") == ("", None)
108
        assert f("a.55bc") == ("a.55bc", None)
109
110
111
if __name__ == "__main__":
112
    pytest.main()
113