Passed
Push — master ( f4e57c...929827 )
by Cyb3r
01:59 queued 11s
created

tests.test_main   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A MetaStalkTests.test_directory() 0 10 1
A MetaStalkTests.test_empty_path() 0 4 2
A MetaStalkTests.test_failed_export() 0 11 2
A MetaStalkTests.test_html_export() 0 19 3
A MetaStalkTests.test_files() 0 11 1
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
class MetaStalkTests(unittest.TestCase):
11
    """MetStalkTests.
12
13
    Test Suite for MetaStalk
14
15
    """
16
17
    def test_empty_path(self):
18
        """Shows result for no path input."""
19
        with self.assertRaises(FileNotFoundError):
20
            main.start()
21
22
    def test_directory(self):
23
        """Results for a directory.
24
        """
25
        arguments = Namespace(
26
            files=['./ExamplePhotos/'],
27
            alphabetic=False,
28
            loglevel=30, test=True, no_open=True,
29
            export=None)
30
        metastalk = main.MetaStalk()
31
        self.assertEqual(metastalk.run(arguments), None)
32
33
    def test_files(self):
34
        """Results for files."""
35
        arguments = Namespace(
36
            files=['./ExamplePhotos/22-canon_tags.jpg', './ExamplePhotos/32-lens_data.jpeg'],
37
            alphabetic=True,
38
            no_open=True,
39
            loglevel=30,
40
            test=True,
41
            export=None)
42
        metastalk = main.MetaStalk()
43
        self.assertEqual(metastalk.run(arguments), None)
44
45
    def test_html_export(self):
46
        """Test to see html files got exported."""
47
        arguments = Namespace(
48
            files=['./ExamplePhotos/22-canon_tags.jpg', './ExamplePhotos/32-lens_data.jpeg'],
49
            loglevel=30,
50
            alphabetic=False,
51
            no_open=True,
52
            test=True,
53
            export="html",
54
            output="metastalk_exports")
55
        metastalk = main.MetaStalk()
56
        metastalk.run(arguments)
57
        test_passed = True
58
        filenames = ["Focal", "GPS", "Manufacturer", "Model", "Producer", "Stats", "Timestamp"]
59
        for required_file in filenames:
60
            if not os.path.isfile(f"metastalk_exports/{required_file}.html"):
61
                print(f"missing file {required_file}")
62
                test_passed = False
63
        self.assertTrue(test_passed)
64
65
    def test_failed_export(self):
66
        """Test for export fail."""
67
        arguments = Namespace(
68
            files=['./ExamplePhotos/'], loglevel=30, test=True,
69
            alphabetic=False,
70
            no_open=True,
71
            export="pdf",
72
            output="metastalk_exports")
73
        metastalk = main.MetaStalk()
74
        with self.assertRaises(EnvironmentError):
75
            metastalk.run(arguments)
76