Issues (931)

tests/model/test_taxonomy.py (20 issues)

1
import pytest
0 ignored issues
show
Missing module docstring
Loading history...
Unable to import 'pytest'
Loading history...
2
3
from mandos import MandosResources
4
from mandos.model.caches import TaxonomyFactories
5
from mandos.model.taxonomy import Taxon, Taxonomy, _Taxon
6
7
8
class TestFind:
0 ignored issues
show
Missing class docstring
Loading history...
9
    def test_find(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
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...
10
        tax = TaxonomyFactories.from_vertebrata().load(7742)
11
        assert len(tax) == 100670
12
        assert tax.roots == [Taxon(7742, "Vertebrata", None, set())]
13
        assert len(tax.roots[0].descendents) == 100669
14
        assert tax[7742] is not None
15
        assert tax[7742].name == "Vertebrata"
16
        assert tax[7742].parent is None
17
        assert tax[117571].id == 117571
18
        assert tax[117571].name == "Euteleostomi"
19
        assert tax[10116].name == "Rattus norvegicus"
20
        assert 117571 in tax
21
        assert [c.id for c in tax[117571].children] == [7898, 8287]
22
        with pytest.raises(KeyError):
23
            assert tax[3343463643446436347457475]
24
        assert tax.get(3343463643446436347457475) is None
25
        assert tax.get(117571).id == 117571
26
        assert 117571 in tax
27
        assert 13745754745745 not in tax
28
29
    def test_empty(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
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...
30
        tax = Taxonomy({})
31
        assert len(tax) == 0
32
        assert tax.roots == []
33
34
    def test_root_leaf(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
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...
35
        taxon = Taxon(1, "abc", None, set())
36
        tax = Taxonomy.from_list([taxon])
37
        assert len(tax) == 1
38
        assert tax.roots == [taxon]
39
        assert tax.leaves == [taxon]
40
41
    def test_double(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
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...
42
        a = _Taxon(1, "a", None, set())
0 ignored issues
show
Coding Style Naming introduced by
Variable name "a" 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...
43
        b = _Taxon(2, "b", a, set())
0 ignored issues
show
Coding Style Naming introduced by
Variable name "b" 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...
44
        a.add_child(b)
45
        tax = Taxonomy.from_list([a, b])
46
        assert len(tax) == 2
47
        assert tax.roots == [a]
48
        assert tax.leaves == [b]
49
        assert set(tax.taxa) == {a, b}
50
        under = tax.subtree(1)
51
        assert len(under) == 2
52
        assert under[1] == a
53
        assert under[2] == b
54
        under = tax.subtree(2)
55
        assert len(under) == 1
56
        assert under[2] == b
57
58
    def test_sort(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
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...
59
        a = _Taxon(10, "z", None, set())
0 ignored issues
show
Coding Style Naming introduced by
Variable name "a" 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...
60
        b = _Taxon(2, "a", a, set())
0 ignored issues
show
Coding Style Naming introduced by
Variable name "b" 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...
61
        c = _Taxon(4, "b", a, set())
0 ignored issues
show
Coding Style Naming introduced by
Variable name "c" 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...
62
        assert b < c, f"{b} vs {c}"
63
        assert b < c < a, f"{a} vs {b} vs {c}"
64
65
    def test_real(self):
0 ignored issues
show
Missing function or method docstring
Loading history...
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...
66
        path = MandosResources.path("7742.tab.gz")
67
        tax = Taxonomy.from_path(path)
68
        assert len(tax) == 100670
69
        tax = tax.subtree(117571)
70
        # number from https://www.uniprot.org/taxonomy/117571
71
        assert len(tax) == 97993
72
73
74
if __name__ == "__main__":
75
    pytest.main()
76