Completed
Push — develop ( c97d07...11b882 )
by Kale
01:01
created

tests.PathTests   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 23
Duplicated Lines 0 %
Metric Value
dl 0
loc 23
rs 10
wmc 11
1
# -*- coding: utf-8 -*-
2
import logging
3
4
from testtools import TestCase
5
6
from auxlib import logz
7
from auxlib.path import open_package_file, PackageFile
8
9
log = logging.getLogger(__name__)
10
11
12
class PathTests(TestCase):
13
14
    @classmethod
15
    def setUpClass(cls):
16
        logz.set_root_level(logging.INFO)
17
        logz.attach_stderr(logging.DEBUG)
18
        assert not logz.attach_stderr()
19
20
    @classmethod
21
    def tearDownClass(self):
22
        logz.detach_stderr()
23
        assert not logz.detach_stderr()
24
25
    def test_find_real_file(self):
26
        fh = open_package_file('requirements/test.txt', None)
27
        lines = fh.readlines()
28
        fh.close()
29
        assert any(line.startswith('testtools') for line in lines)
30
31
    def test_find_python_file_in_package(self):
32
        with PackageFile('path.py', 'auxlib') as fh:
33
            lines = fh.readlines()
34
            assert any(line.startswith(b'class PackageFile(object):') for line in lines)
35
36
    # TODO: Write tests for "look for file in site-packages"
37
    # def test_find_python_file_in_site_packages(self):
38
    #     # with PackageFile('__init__.py', 'testtools') as fh:  # package resource file
39
    #     # with PackageFile('LICENSE', 'py.test') as fh:  # real file
40
    #     with PackageFile('PKG-INFO', 'pytest') as fh:
41
    #         lines = fh.readlines()
42
    #         assert any(line.startswith('__version__') for line in lines)
43
    #     assert False
44