TestDf3Tools   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 66
rs 10
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_main() 0 9 3
A test_full_cycle() 0 18 3
A tearDown() 0 9 3
A test_no_layers() 0 10 2
A test_abscent_file() 0 10 2
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