Completed
Pull Request — master (#68)
by Jace
03:27
created

TestWindowsManager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 29
loc 29
rs 10
wmc 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# pylint: disable=misplaced-comparison-constant,no-self-use
2
3
import pytest
4
5
from mine.manager import get_manager, LinuxManager, MacManager, WindowsManager
6
from mine.models import Application
7
8
9
class TestLinuxManager:
10
    """Unit tests for the Linux manager class."""
11
12
    manager = get_manager('Linux')
13
14
    def test_init(self):
15
        """Verify the OS is detected correctly."""
16
        assert isinstance(self.manager, LinuxManager)
17
18
    def test_is_running_false(self):
19
        """Verify a process can be detected as not running."""
20
        pytest.skip("TODO: implement test")
21
        application = Application('fake-program-for-mine')
22
        application.versions.linux = 'fake_program_for_mine.sh'
23
        assert False is self.manager.is_running(application)
24
25
    @pytest.mark.linux_only
26
    def test_is_running_true(self):
27
        """Verify a process can be detected as running."""
28
        pytest.skip("TODO: implement test")
29
30
    def test_is_running_none(self):
31
        """Verify a process can be detected as untracked."""
32
        application = Application('fake-program-for-mine')
33
        assert None is self.manager.is_running(application)
34
35
36
class TestMacManager:
37
    """Unit tests for the Mac manager class."""
38
39
    manager = get_manager('Darwin')
40
41
    def test_init(self):
42
        """Verify the OS is detected correctly."""
43
        assert isinstance(self.manager, MacManager)
44
45
    def test_is_running_false(self):
46
        """Verify a process can be detected as not running."""
47
        application = Application('fake-program-for-mine')
48
        application.versions.mac = 'FakeProgramForMine.app'
49
        assert False is self.manager.is_running(application)
50
51
    @pytest.mark.mac_only
52
    def test_is_running_true(self):
53
        """Verify a process can be detected as running."""
54
        application = Application('finder')
55
        application.versions.mac = 'Finder.app'
56
        assert True is self.manager.is_running(application)
57
58
    def test_is_running_none(self):
59
        """Verify a process can be detected as untracked."""
60
        application = Application('fake-program-for-mine')
61
        assert None is self.manager.is_running(application)
62
63
    @pytest.mark.mac_only
64
    def test_stop(self):
65
        """Verify a process can be stopped."""
66
        application = Application('mail')
67
        application.versions.mac = 'Mail.app'
68
        self.manager.stop(application)
69
        assert not self.manager.is_running(application)
70
71
72
class TestWindowsManager:
73
    """Unit tests for the Windows manager class."""
74
75
    manager = get_manager('Windows')
76
77
    def test_init(self):
78
        """Verify the OS is detected correctly."""
79
        assert isinstance(self.manager, WindowsManager)
80
81
    def test_is_running_false(self):
82
        """Verify a process can be detected as not running."""
83
        pytest.skip("TODO: implement test")
84
        application = Application('fake-program-for-mine')
85
        application.versions.windows = 'FakeProgramForMine.exe'
86
        assert False is self.manager.is_running(application)
87
88
    @pytest.mark.windows_only
89
    def test_is_running_true(self):
90
        """Verify a process can be detected as running."""
91
        pytest.skip("TODO: implement test")
92
        application = Application('explorer')
93
        application.versions.windows = 'explorer.exe'
94
        assert True is self.manager.is_running(application)
95
96
    def test_is_running_none(self):
97
        """Verify a process can be detected as untracked."""
98
        application = Application('fake-program-for-mine')
99
        assert None is self.manager.is_running(application)
100