1
- """Unit tests for docklib."""
1
+ """unit.py
2
+
3
+ Unit tests for docklib. NOTE: These tests are designed to mutate the logged in
4
+ user's dock. If all tests pass, the end state should be the same as the
5
+ beginning state, but be aware that there is some possibility of undesired
6
+ modifications remaining if the tests fail.
7
+ """
2
8
3
9
import os
4
10
import types
9
15
10
16
11
17
class TestDocklib (unittest .TestCase ):
12
- """Unit test class."""
18
+ """Unit test class. Functions are numbered in order to ensure a specific
19
+ execution order."""
13
20
14
21
def setUp (self ):
15
22
self .dock = docklib .Dock ()
16
23
17
- def test_import (self ):
24
+ def test_00_import (self ):
18
25
"""Ensure docklib imports successfully as a module."""
19
26
self .assertIs (type (docklib ), types .ModuleType )
20
27
21
- def test_init (self ):
28
+ def test_05_init (self ):
22
29
"""Ensure docklib successfully reads the macOS dock."""
23
30
self .assertIsInstance (self .dock , docklib .Dock )
24
31
25
- def test_sections (self ):
32
+ def test_10_sections (self ):
26
33
"""Ensure docklib retrieves the expected dock sections."""
27
34
actual_sections = list (self .dock .items .keys ())
28
35
# pylint: disable=W0212
29
36
self .assertEqual (sorted (actual_sections ), sorted (docklib .Dock ._SECTIONS ))
30
37
# pylint: enable=W0212
31
38
32
- def test_item_keys (self ):
39
+ def test_15_item_keys (self ):
33
40
"""Ensure docklib does not encounter unexpected dock item keys."""
34
41
sections = ["persistent-apps" , "persistent-others" ]
35
42
actual_keys = []
@@ -40,7 +47,7 @@ def test_item_keys(self):
40
47
actual_keys = list (set (actual_keys ))
41
48
self .assertEqual (sorted (actual_keys ), sorted (expected_keys ))
42
49
43
- def test_tile_data_keys (self ):
50
+ def test_20_tile_data_keys (self ):
44
51
"""Ensure docklib does not encounter unexpected tile-data keys."""
45
52
sections = ["persistent-apps" , "persistent-others" ]
46
53
expected_keys = [
@@ -64,7 +71,7 @@ def test_tile_data_keys(self):
64
71
for key in item ["tile-data" ].keys ():
65
72
self .assertIn (key , expected_keys )
66
73
67
- def test_tile_types (self ):
74
+ def test_25_tile_types (self ):
68
75
"""Ensure docklib does not encounter unexpected tile-types."""
69
76
sections = ["persistent-apps" , "persistent-others" ]
70
77
expected_types = [
@@ -78,7 +85,7 @@ def test_tile_types(self):
78
85
for item in self .dock .items [section ]:
79
86
self .assertIn (item ["tile-type" ], expected_types )
80
87
81
- def test_add_app (self ):
88
+ def test_30_add_app (self ):
82
89
"""Ensure docklib can add apps to the dock."""
83
90
item = self .dock .makeDockAppEntry ("/System/Applications/Chess.app" )
84
91
old_len = len (self .dock .items ["persistent-apps" ])
@@ -88,15 +95,15 @@ def test_add_app(self):
88
95
new_len = len (self .dock .items ["persistent-apps" ])
89
96
self .assertEqual (new_len , old_len + 1 )
90
97
91
- def test_find_app (self ):
98
+ def test_35_find_app (self ):
92
99
"""Ensure docklib can find apps in the dock."""
93
100
app_idx = self .dock .findExistingLabel ("Chess" , section = "persistent-apps" )
94
101
self .assertGreaterEqual (app_idx , 0 )
95
102
96
103
app_idx = self .dock .findExistingLabel ("FooBarApp" , section = "persistent-apps" )
97
104
self .assertEqual (app_idx , - 1 )
98
105
99
- def test_remove_app (self ):
106
+ def test_40_remove_app (self ):
100
107
"""Ensure docklib can remove apps from the dock."""
101
108
old_len = len (self .dock .items ["persistent-apps" ])
102
109
self .dock .removeDockEntry ("Chess" )
@@ -105,7 +112,7 @@ def test_remove_app(self):
105
112
new_len = len (self .dock .items ["persistent-apps" ])
106
113
self .assertEqual (new_len , old_len - 1 )
107
114
108
- def test_add_other (self ):
115
+ def test_45_add_other (self ):
109
116
"""Ensure docklib can add other items to the dock."""
110
117
item = self .dock .makeDockOtherEntry (
111
118
os .path .expanduser ("~/Library/Application Support" )
@@ -117,7 +124,7 @@ def test_add_other(self):
117
124
new_len = len (self .dock .items ["persistent-others" ])
118
125
self .assertEqual (new_len , old_len + 1 )
119
126
120
- def test_find_other (self ):
127
+ def test_50_find_other (self ):
121
128
"""Ensure docklib can find other items in the dock."""
122
129
other_idx = self .dock .findExistingLabel (
123
130
"Application Support" , section = "persistent-others"
@@ -129,7 +136,7 @@ def test_find_other(self):
129
136
)
130
137
self .assertEqual (other_idx , - 1 )
131
138
132
- def test_remove_other (self ):
139
+ def test_55_remove_other (self ):
133
140
"""Ensure docklib can remove other items from the dock."""
134
141
old_len = len (self .dock .items ["persistent-others" ])
135
142
self .dock .removeDockEntry ("Application Support" )
@@ -138,7 +145,7 @@ def test_remove_other(self):
138
145
new_len = len (self .dock .items ["persistent-others" ])
139
146
self .assertEqual (new_len , old_len - 1 )
140
147
141
- def test_add_url (self ):
148
+ def test_60_add_url (self ):
142
149
"""Ensure docklib can add url items to the dock."""
143
150
item = self .dock .makeDockOtherURLEntry ("https://www.apple.com" , "Apple Inc" )
144
151
old_len = len (self .dock .items ["persistent-others" ])
@@ -148,7 +155,14 @@ def test_add_url(self):
148
155
new_len = len (self .dock .items ["persistent-others" ])
149
156
self .assertEqual (new_len , old_len + 1 )
150
157
151
- def test_remove_url (self ):
158
+ def test_65_find_url (self ):
159
+ """Ensure docklib can find url items in the dock."""
160
+ other_idx = self .dock .findExistingLabel (
161
+ "Apple Inc" , section = "persistent-others"
162
+ )
163
+ self .assertGreaterEqual (other_idx , 0 )
164
+
165
+ def test_70_remove_url (self ):
152
166
"""Ensure docklib can remove url items from the dock."""
153
167
old_len = len (self .dock .items ["persistent-others" ])
154
168
self .dock .removeDockURLEntry ("https://www.apple.com" )
@@ -157,7 +171,7 @@ def test_remove_url(self):
157
171
new_len = len (self .dock .items ["persistent-others" ])
158
172
self .assertEqual (new_len , old_len - 1 )
159
173
160
- def test_add_spacer (self ):
174
+ def test_75_add_spacer (self ):
161
175
"""Ensure docklib can add a spacer item to the dock."""
162
176
item = self .dock .makeDockAppSpacer ()
163
177
old_len = len (self .dock .items ["persistent-apps" ])
@@ -167,7 +181,7 @@ def test_add_spacer(self):
167
181
new_len = len (self .dock .items ["persistent-apps" ])
168
182
self .assertEqual (new_len , old_len + 1 )
169
183
170
- def test_remove_spacer (self ):
184
+ def test_80_remove_spacer (self ):
171
185
"""Ensure docklib can remove a spacer item from the dock."""
172
186
old_len = len (self .dock .items ["persistent-apps" ])
173
187
del self .dock .items ["persistent-apps" ][0 ]
0 commit comments