Passed
Push — master ( 929827...929f74 )
by Cyb3r
02:12
created

tests.test_main.MetaStalkTests.test_heic()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 1
dl 0
loc 12
rs 9.85
c 0
b 0
f 0
1
"""Tests for MetaStalk.
2
"""
3
import unittest
4
from argparse import Namespace
5
import os
6
7
from MetaStalk import main
8
9
10
try:
11
    import pyheif  # noqa: F401 pylint: disable=unused-import
12
    heic_enabled = True
13
except ImportError:
14
    heic_enabled = False
15
16
17
class MetaStalkTests(unittest.TestCase):
18
    """MetStalkTests.
19
20
    Test Suite for MetaStalk
21
22
    """
23
24
    def test_empty_path(self):
25
        """Shows result for no path input."""
26
        with self.assertRaises(FileNotFoundError):
27
            main.start()
28
29
    def test_directory(self):
30
        """Results for a directory.
31
        """
32
        arguments = Namespace(
33
            files=['./ExamplePhotos/'],
34
            alphabetic=False,
35
            loglevel=30,
36
            test=True,
37
            no_open=True,
38
            export=None)
39
        metastalk = main.MetaStalk()
40
        self.assertEqual(metastalk.run(arguments), None)
41
42
    def test_files(self):
43
        """Results for files."""
44
        arguments = Namespace(
45
            files=['./ExamplePhotos/22-canon_tags.jpg', './ExamplePhotos/32-lens_data.jpeg'],
46
            alphabetic=True,
47
            no_open=True,
48
            loglevel=30,
49
            test=True,
50
            export=None)
51
        metastalk = main.MetaStalk()
52
        self.assertEqual(metastalk.run(arguments), None)
53
54
    def test_html_export(self):
55
        """Test to see html files got exported."""
56
        arguments = Namespace(
57
            files=['./ExamplePhotos/22-canon_tags.jpg', './ExamplePhotos/32-lens_data.jpeg'],
58
            loglevel=30,
59
            alphabetic=False,
60
            no_open=True,
61
            test=True,
62
            export="html",
63
            output="metastalk_exports")
64
        metastalk = main.MetaStalk()
65
        metastalk.run(arguments)
66
        test_passed = True
67
        filenames = ["Focal", "GPS", "Manufacturer", "Model", "Producer", "Stats", "Timestamp"]
68
        for required_file in filenames:
69
            if not os.path.isfile(f"metastalk_exports/{required_file}.html"):
70
                print(f"missing file {required_file}")
71
                test_passed = False
72
        self.assertTrue(test_passed)
73
74
    def test_html_size(self):
75
        """Test to see html that the offline html files are bigger"""
76
        arguments = Namespace(
77
            files=['./ExamplePhotos/22-canon_tags.jpg', './ExamplePhotos/32-lens_data.jpeg'],
78
            loglevel=20,
79
            alphabetic=False,
80
            no_open=True,
81
            test=True,
82
            export="html_offline",
83
            output="metastalk_exports_offline")
84
        metastalk = main.MetaStalk()
85
        metastalk.run(arguments)
86
        test_passed = True
87
        filenames = ["Focal", "GPS", "Manufacturer", "Model", "Producer", "Stats", "Timestamp"]
88
        for required_file in filenames:
89
            file_size_normal = os.stat(f"metastalk_exports/{required_file}.html").st_size
90
            file_size_offline = os.stat(f"metastalk_exports_offline/{required_file}.html").st_size
91
            if file_size_normal > file_size_offline:
92
                print(f"Wrong File Size for: {required_file}")
93
                test_passed = False
94
        self.assertTrue(test_passed)
95
96
    def test_failed_export(self):
97
        """Test for export fail."""
98
        arguments = Namespace(
99
            files=['./ExamplePhotos/'],
100
            loglevel=30,
101
            test=True,
102
            alphabetic=False,
103
            no_open=True,
104
            export="pdf",
105
            output="metastalk_exports")
106
        metastalk = main.MetaStalk()
107
        with self.assertRaises(EnvironmentError):
108
            metastalk.run(arguments)
109
110
    def test_no_heic(self):
111
        """Tests if pyheif is not installed"""
112
        arguments = Namespace(
113
            files=['./ExamplePhotos/heic'],
114
            alphabetic=False,
115
            loglevel=30,
116
            test=True,
117
            no_open=True,
118
            export="html",
119
            output="metastalk_exports")
120
        metastalk = main.MetaStalk()
121
        self.assertEqual(metastalk.run(arguments), None)
122
123
    @unittest.skipUnless(heic_enabled, "Windows doesn't have pyheif")
124
    def test_heic(self):
125
        """Test if pyheif is installed"""
126
        arguments = Namespace(
127
            files=['./ExamplePhotos/'],
128
            alphabetic=True,
129
            loglevel=30,
130
            test=True,
131
            no_open=False,
132
            export=None)
133
        metastalk = main.MetaStalk()
134
        self.assertEqual(metastalk.run(arguments), None)
135