|
1
|
|
|
""" |
|
2
|
|
|
Test suite for df3 tools module. |
|
3
|
|
|
|
|
4
|
|
|
""" |
|
5
|
|
|
|
|
6
|
|
|
import unittest |
|
7
|
|
|
import glob |
|
8
|
|
|
import os |
|
9
|
|
|
import sys |
|
10
|
|
|
|
|
11
|
|
|
from df3tools import df3split, df3combine |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
class TestDf3Tools(unittest.TestCase): |
|
15
|
|
|
""" |
|
16
|
|
|
Tests for df3split and df3combine tools. |
|
17
|
|
|
|
|
18
|
|
|
""" |
|
19
|
|
|
|
|
20
|
|
|
def tearDown(self): |
|
21
|
|
|
""" |
|
22
|
|
|
Clean up .tga and .df3 files after test. |
|
23
|
|
|
|
|
24
|
|
|
""" |
|
25
|
|
|
for filename in glob.glob("*.tga"): |
|
26
|
|
|
os.remove(filename) |
|
27
|
|
|
for filename in glob.glob("*.df3"): |
|
28
|
|
|
os.remove(filename) |
|
29
|
|
|
|
|
30
|
|
|
def test_full_cycle(self): |
|
31
|
|
|
""" |
|
32
|
|
|
Test that DF3 split and combine produce same file. |
|
33
|
|
|
|
|
34
|
|
|
""" |
|
35
|
|
|
args = sys.argv |
|
36
|
|
|
sys.argv = ['df3split.py', 'data/clouds.df3'] |
|
37
|
|
|
df3split.main() |
|
38
|
|
|
self.assertEqual(len(glob.glob("*.tga")), 133) |
|
39
|
|
|
sys.argv = ['df3split.py', 'clouds.df3'] |
|
40
|
|
|
df3combine.main() |
|
41
|
|
|
with open('data/clouds.df3', "rb") as df3_file: |
|
42
|
|
|
orig_content = df3_file.read() |
|
43
|
|
|
with open('clouds.df3', "rb") as df3_file: |
|
44
|
|
|
combined_content = df3_file.read() |
|
45
|
|
|
self.assertEqual(orig_content, combined_content, |
|
46
|
|
|
"Original file differs from combined file.") |
|
47
|
|
|
sys.argv = args |
|
48
|
|
|
|
|
49
|
|
|
def test_main(self): |
|
50
|
|
|
""" |
|
51
|
|
|
Test main() functions are callable and raise SystemExit. |
|
52
|
|
|
|
|
53
|
|
|
""" |
|
54
|
|
|
with self.assertRaises(SystemExit): |
|
55
|
|
|
df3split.main() |
|
56
|
|
|
with self.assertRaises(SystemExit): |
|
57
|
|
|
df3combine.main() |
|
58
|
|
|
|
|
59
|
|
|
@unittest.skip("Raise FileNotFoundError") |
|
60
|
|
|
def test_abscent_file(self): |
|
|
|
|
|
|
61
|
|
|
""" |
|
62
|
|
|
Test behavior when DF3 file not found |
|
63
|
|
|
|
|
64
|
|
|
""" |
|
65
|
|
|
args = sys.argv |
|
66
|
|
|
sys.argv = ['df3split.py', 'data/nofile.df3'] |
|
67
|
|
|
df3split.main() |
|
68
|
|
|
sys.argv = args |
|
69
|
|
|
|
|
70
|
|
|
def test_no_layers(self): |
|
71
|
|
|
""" |
|
72
|
|
|
Test behavior when images not found |
|
73
|
|
|
|
|
74
|
|
|
""" |
|
75
|
|
|
args = sys.argv |
|
76
|
|
|
sys.argv = ['df3combine.py', '-p', 'nolayer', 'data/nofile.df3'] |
|
77
|
|
|
with self.assertRaises(df3combine.Df3Exception): |
|
78
|
|
|
df3combine.main() |
|
79
|
|
|
sys.argv = args |
|
80
|
|
|
|
If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example
could be written as