Passed
Push — main ( d2739b...2ca903 )
by Douglas
02:55 queued 01:10
created

tests.pocketutils.tools.test_filesys_tools.TestFilesysTools.test_get_env_info()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 0
loc 7
rs 10
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
0 ignored issues
show
Bug introduced by
The name core does not seem to exist in module pocketutils.
Loading history...
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
50
if __name__ == "__main__":
51
    pytest.main()
52