1
|
|
|
# pylint: disable=misplaced-comparison-constant,no-self-use |
|
|
|
|
2
|
|
|
|
3
|
|
|
import pytest |
4
|
|
|
|
5
|
|
|
from mine.application import Application, Applications |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TestApplication: |
9
|
|
|
|
10
|
|
|
"""Unit tests for the application class.""" |
11
|
|
|
|
12
|
|
|
app1 = Application('iTunes') |
13
|
|
|
app1.versions.mac = 'iTunes.app' |
14
|
|
|
app2 = Application('HipChat') |
15
|
|
|
app3 = Application('Sublime Text') |
16
|
|
|
app3.versions.linux = 'sublime_text' |
17
|
|
|
app4 = Application('hipchat') |
18
|
|
|
|
19
|
|
|
str_application = [ |
20
|
|
|
("iTunes", app1), |
21
|
|
|
("HipChat", app2), |
22
|
|
|
("Sublime Text", app3), |
23
|
|
|
("hipchat", app4), |
24
|
|
|
] |
25
|
|
|
|
26
|
|
|
@pytest.mark.parametrize("string,application", str_application) |
27
|
|
|
def test_str(self, string, application): |
28
|
|
|
"""Verify applications can be converted to strings.""" |
29
|
|
|
assert string == str(application) |
30
|
|
|
|
31
|
|
|
def test_eq(self): |
32
|
|
|
"""Verify applications can be equated.""" |
33
|
|
|
assert self.app2 == self.app4 |
34
|
|
|
assert self.app1 != self.app3 |
35
|
|
|
|
36
|
|
|
def test_lt(self): |
37
|
|
|
"""Verify applications can be sorted.""" |
38
|
|
|
assert self.app2 < self.app1 |
39
|
|
|
assert self.app3 > self.app2 |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class TestApplications: |
43
|
|
|
|
44
|
|
|
"""Unit tests for lists of applications.""" |
45
|
|
|
|
46
|
|
|
apps = Applications([TestApplication.app1, TestApplication.app2]) |
47
|
|
|
|
48
|
|
|
def test_get(self): |
49
|
|
|
"""Verify an application can be found in a list.""" |
50
|
|
|
app = self.apps.get('itunes') |
51
|
|
|
assert 'iTunes' == app.name |
52
|
|
|
|
53
|
|
|
def test_get_missing(self): |
54
|
|
|
"""Verify an invalid names raise an assertion.""" |
55
|
|
|
with pytest.raises(AssertionError): |
56
|
|
|
self.apps.get('fake') |
57
|
|
|
|