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

TestFilesysTools.test_get_info()   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nop 1
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
1
from pathlib import Path
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.exceptions import ParsingError
6
from pocketutils.tools.filesys_tools import FilesysTools
7
8
9
def load(parts):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
10
    if isinstance(parts, str):
11
        parts = [parts]
12
    return Path(Path(__file__).parent.parent.parent / "resources" / "core", *parts)
13
14
15
class TestFilesysTools:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
16
    def test_read_lines(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...
17
        assert list(FilesysTools.read_lines_file(load("lines.lines"))) == [
18
            "line1 = 5",
19
            "line2=5",
20
            "",
21
            "#line3",
22
            "line4 = a",
23
        ]
24
        assert list(FilesysTools.read_lines_file(load("lines.lines"), ignore_comments=True)) == [
25
            "line1 = 5",
26
            "line2=5",
27
            "line4 = a",
28
        ]
29
30
    def test_read_properties(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...
31
        f = FilesysTools.read_properties_file
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...
32
        expected = {"line1": "5", "line2": "5", "line4": "a"}
33
        assert dict(f(load("lines.lines"))) == expected
34
        with pytest.raises(ParsingError):
35
            f(load("bad1.properties"))
36
        with pytest.raises(ParsingError):
37
            f(load("bad2.properties"))
38
39
    def test_get_info(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...
40
        file = load("lines.lines")
41
        info = FilesysTools.get_info(file)
42
        assert info.is_file
43
        assert info.mod_or_create_dt is not None
44
        info = FilesysTools.get_info(".")
45
        assert info.is_dir
46
        assert not info.is_file
47
        assert info.mod_or_create_dt is not None
48
49
    def test_get_env_info(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...
50
        data = FilesysTools.get_env_info(include_insecure=True)
51
        assert len(data) > 20
52
        assert "pid" in data
53
        assert "disk_used" in data
54
        assert "hostname" in data
55
        assert "locale" in data
56
57
    def test_list_imports(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...
58
        data = FilesysTools.list_package_versions()
59
        assert len(data) > 5
60
        assert "orjson" in data
61
        assert data["orjson"].startswith("3.")  # change when updated
62
63
64
if __name__ == "__main__":
65
    pytest.main()
66