1
|
|
|
import os |
2
|
|
|
import unittest |
3
|
|
|
from datetime import datetime |
4
|
|
|
from dirutility.walk import DirPaths |
5
|
|
|
from dirutility.walk.walk import md5_hash |
6
|
|
|
from tests import * |
7
|
|
|
|
8
|
|
|
CONSOLE_STREAM = True |
9
|
|
|
|
10
|
|
|
|
11
|
|
View Code Duplication |
class TestWalk(unittest.TestCase): |
|
|
|
|
12
|
|
|
|
13
|
|
|
def test_DirPaths_multiprocess(self): |
14
|
|
|
paths = DirPaths(directory, full_paths=True, parallelize=True, console_stream=CONSOLE_STREAM).walk() |
15
|
|
|
for i in paths: |
16
|
|
|
self.assertTrue(os.path.exists(i)) |
17
|
|
|
|
18
|
|
|
def test_DirPaths_sequential(self): |
19
|
|
|
paths = DirPaths(directory, full_paths=True, parallelize=False, console_stream=CONSOLE_STREAM).walk() |
20
|
|
|
for i in paths: |
21
|
|
|
self.assertTrue(os.path.exists(i)) |
22
|
|
|
|
23
|
|
|
def test_DirPaths_sequential_nofilters(self): |
24
|
|
|
paths = DirPaths(directory, full_paths=True, parallelize=False, to_exclude=False, |
25
|
|
|
console_stream=CONSOLE_STREAM).walk() |
26
|
|
|
for i in paths: |
27
|
|
|
self.assertTrue(os.path.exists(i)) |
28
|
|
|
|
29
|
|
|
def test_DirPaths_hash(self): |
30
|
|
|
paths = DirPaths(directory, full_paths=True, parallelize=False, hash_files=True, |
31
|
|
|
console_stream=CONSOLE_STREAM).walk() |
32
|
|
|
for path, _hash in paths: |
33
|
|
|
self.assertTrue(os.path.exists(path)) |
34
|
|
|
self.assertEqual(_hash, md5_hash(path)) |
35
|
|
|
|
36
|
|
|
def test_DirPaths_created_at(self): |
37
|
|
|
dp = DirPaths(directory, full_paths=True, parallelize=True, console_stream=CONSOLE_STREAM) |
38
|
|
|
dp.walk() |
39
|
|
|
file_created = dp.creation_dates(sort=True) |
40
|
|
|
|
41
|
|
|
for path, created_at in file_created: |
42
|
|
|
self.assertTrue(os.path.exists(path)) |
43
|
|
|
self.assertTrue(isinstance(created_at, datetime)) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
if __name__ == '__main__': |
47
|
|
|
unittest.main() |
48
|
|
|
|