Test Failed
Pull Request — master (#9)
by Stephen
06:04
created

tests.test_archivefile.TestArchive.test_tardir()   B

Complexity

Conditions 6

Size

Total Lines 42
Code Lines 30

Duplication

Lines 42
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
eloc 30
nop 1
dl 42
loc 42
rs 8.2266
c 0
b 0
f 0
1
import os
2
import unittest
3
from time import sleep
4
5
from dirutility.open.open import tardir
6
7
8 View Code Duplication
class TestArchive(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    def test_tardir(self):
10
        tempfile = '/Users/Shared/kasdkfasdf.txt'
11
        with open(tempfile, 'w') as wfd:
12
            wfd.write(tempfile)
13
        with open(tempfile, 'r') as rfd1, open(tempfile, 'r') as rfd2:
14
            paths = {
15
                'abc': 'abc abc abc',
16
                'kbs': {
17
                    'haha': {
18
19
                    },
20
                    'yoyo': {
21
                        'haha': rfd1
22
                    }
23
                },
24
                'abcd': {
25
                    'kbs': rfd2
26
                },
27
            }
28
            with tardir('/Users/Shared/haha.tar.gz', **paths) as tarfile:
29
                self.assertTrue(os.path.exists(tarfile.filepath))
30
            self.assertFalse(os.path.exists(tarfile.filepath))
31
        with open(tempfile, 'r') as rfd1, open(tempfile, 'r') as rfd2:
32
            paths = {
33
                'abc': 'abc abc abc',
34
                'kbs': {
35
                    'haha': {
36
37
                    },
38
                    'yoyo': {
39
                        'haha': rfd1
40
                    }
41
                },
42
                'abcd': {
43
                    'kbs': rfd2
44
                },
45
            }
46
            with tardir('/Users/Shared/haha.zip', **paths, mode='w:zip', withdir=True) as tarfile:
47
                self.assertTrue(os.path.exists(tarfile.filepath))
48
                sleep(10)
49
            self.assertFalse(os.path.exists(tarfile.filepath))
50
        os.remove(tempfile)
51
52
53
if __name__ == '__main__':
54
    unittest.main()
55