TestDf3Tools.test_full_cycle()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
dl 0
loc 18
rs 9.4285
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
    def test_abscent_file(self):
60
        """
61
        Test behavior when DF3 file not found
62
63
        """
64
        args = sys.argv
65
        with self.assertRaises(df3combine.Df3Exception):
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