| Total Complexity | 6 |
| Total Lines | 55 |
| Duplicated Lines | 78.18 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 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): |
|
|
|
|||
| 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 |