1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from os import sep
24 from unittest import TestCase
25
26
27 import lib.io
28
29
31 """Unit tests for the functions of the 'lib.io' module."""
32
33
35 """Test the lib.io.file_root() function with '/tmp/test.xyz'."""
36
37
38 file = '/tmp/test.xyz'
39 root = 'test'
40
41
42 self.assertEqual(lib.io.file_root(file), root)
43
44
46 """Test the lib.io.file_root() function with '/tmp/test.xyz.gz'."""
47
48
49 file = '/tmp/test.xyz.gz'
50 root = 'test'
51
52
53 self.assertEqual(lib.io.file_root(file), root)
54
55
57 """Test for file paths which should remain unmodified by lib.io.get_file_path."""
58
59
60 file1 = 'test'
61 file2 = 'test'+sep+'aaa'
62 file3 = sep+'home'+sep+'test'+sep+'aaa'
63
64
65 self.assertEqual(lib.io.get_file_path(file1), file1)
66 self.assertEqual(lib.io.get_file_path(file2), file2)
67 self.assertEqual(lib.io.get_file_path(file3), file3)
68
69
71 """The modification of file paths by lib.io.get_file_path when a directory is supplied."""
72
73
74 file1 = 'test'
75 file2 = 'test'+sep+'aaa'
76 file3 = sep+'home'+sep+'test'+sep+'aaa'
77
78
79 dir1 = sep+'usr'
80 dir2 = 'usr'
81 dir3 = sep+'usr'
82
83
84 self.assertEqual(lib.io.get_file_path(file1, dir1), dir1+sep+file1)
85 self.assertEqual(lib.io.get_file_path(file2, dir2), dir2+sep+file2)
86 self.assertEqual(lib.io.get_file_path(file3, dir=dir3), dir3+sep+file3)
87
88
90 """The modification of file paths with '~', by lib.io.get_file_path."""
91
92
93 file1 = '~'+sep+'test'
94 file2 = '~'+sep+'test'+sep+'aaa'
95
96
97 self.assertNotEqual(lib.io.get_file_path(file1), file1)
98 self.assertNotEqual(lib.io.get_file_path(file2), file2)
99
100
102 """Test the lib.io.swap_extension function with a file with no extension."""
103
104
105 file_name = lib.io.swap_extension('test', 'txt')
106 self.assertEqual(file_name, 'test.txt')
107
108
110 """Test the lib.io.swap_extension function with a file with an extension."""
111
112
113 file_name = lib.io.swap_extension('test.txt', 'png')
114 self.assertEqual(file_name, 'test.png')
115
116
118 """Test the lib.io.swap_extension function with a file with a double extension."""
119
120
121 file_name = lib.io.swap_extension('test.txt.gz', 'png')
122 self.assertEqual(file_name, 'test.png')
123
124
126 """Test the lib.io.swap_extension function with a file with a broken extension."""
127
128
129 file_name = lib.io.swap_extension('test.', 'png')
130 self.assertEqual(file_name, 'test.png')
131