Skip to content

Commit 81a4f51

Browse files
committed
Number unit tests and add findExistingLabel URL test
1 parent 50e8c37 commit 81a4f51

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

tests/unit.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
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+
"""
28

39
import os
410
import types
@@ -9,27 +15,28 @@
915

1016

1117
class TestDocklib(unittest.TestCase):
12-
"""Unit test class."""
18+
"""Unit test class. Functions are numbered in order to ensure a specific
19+
execution order."""
1320

1421
def setUp(self):
1522
self.dock = docklib.Dock()
1623

17-
def test_import(self):
24+
def test_00_import(self):
1825
"""Ensure docklib imports successfully as a module."""
1926
self.assertIs(type(docklib), types.ModuleType)
2027

21-
def test_init(self):
28+
def test_05_init(self):
2229
"""Ensure docklib successfully reads the macOS dock."""
2330
self.assertIsInstance(self.dock, docklib.Dock)
2431

25-
def test_sections(self):
32+
def test_10_sections(self):
2633
"""Ensure docklib retrieves the expected dock sections."""
2734
actual_sections = list(self.dock.items.keys())
2835
# pylint: disable=W0212
2936
self.assertEqual(sorted(actual_sections), sorted(docklib.Dock._SECTIONS))
3037
# pylint: enable=W0212
3138

32-
def test_item_keys(self):
39+
def test_15_item_keys(self):
3340
"""Ensure docklib does not encounter unexpected dock item keys."""
3441
sections = ["persistent-apps", "persistent-others"]
3542
actual_keys = []
@@ -40,7 +47,7 @@ def test_item_keys(self):
4047
actual_keys = list(set(actual_keys))
4148
self.assertEqual(sorted(actual_keys), sorted(expected_keys))
4249

43-
def test_tile_data_keys(self):
50+
def test_20_tile_data_keys(self):
4451
"""Ensure docklib does not encounter unexpected tile-data keys."""
4552
sections = ["persistent-apps", "persistent-others"]
4653
expected_keys = [
@@ -64,7 +71,7 @@ def test_tile_data_keys(self):
6471
for key in item["tile-data"].keys():
6572
self.assertIn(key, expected_keys)
6673

67-
def test_tile_types(self):
74+
def test_25_tile_types(self):
6875
"""Ensure docklib does not encounter unexpected tile-types."""
6976
sections = ["persistent-apps", "persistent-others"]
7077
expected_types = [
@@ -78,7 +85,7 @@ def test_tile_types(self):
7885
for item in self.dock.items[section]:
7986
self.assertIn(item["tile-type"], expected_types)
8087

81-
def test_add_app(self):
88+
def test_30_add_app(self):
8289
"""Ensure docklib can add apps to the dock."""
8390
item = self.dock.makeDockAppEntry("/System/Applications/Chess.app")
8491
old_len = len(self.dock.items["persistent-apps"])
@@ -88,15 +95,15 @@ def test_add_app(self):
8895
new_len = len(self.dock.items["persistent-apps"])
8996
self.assertEqual(new_len, old_len + 1)
9097

91-
def test_find_app(self):
98+
def test_35_find_app(self):
9299
"""Ensure docklib can find apps in the dock."""
93100
app_idx = self.dock.findExistingLabel("Chess", section="persistent-apps")
94101
self.assertGreaterEqual(app_idx, 0)
95102

96103
app_idx = self.dock.findExistingLabel("FooBarApp", section="persistent-apps")
97104
self.assertEqual(app_idx, -1)
98105

99-
def test_remove_app(self):
106+
def test_40_remove_app(self):
100107
"""Ensure docklib can remove apps from the dock."""
101108
old_len = len(self.dock.items["persistent-apps"])
102109
self.dock.removeDockEntry("Chess")
@@ -105,7 +112,7 @@ def test_remove_app(self):
105112
new_len = len(self.dock.items["persistent-apps"])
106113
self.assertEqual(new_len, old_len - 1)
107114

108-
def test_add_other(self):
115+
def test_45_add_other(self):
109116
"""Ensure docklib can add other items to the dock."""
110117
item = self.dock.makeDockOtherEntry(
111118
os.path.expanduser("~/Library/Application Support")
@@ -117,7 +124,7 @@ def test_add_other(self):
117124
new_len = len(self.dock.items["persistent-others"])
118125
self.assertEqual(new_len, old_len + 1)
119126

120-
def test_find_other(self):
127+
def test_50_find_other(self):
121128
"""Ensure docklib can find other items in the dock."""
122129
other_idx = self.dock.findExistingLabel(
123130
"Application Support", section="persistent-others"
@@ -129,7 +136,7 @@ def test_find_other(self):
129136
)
130137
self.assertEqual(other_idx, -1)
131138

132-
def test_remove_other(self):
139+
def test_55_remove_other(self):
133140
"""Ensure docklib can remove other items from the dock."""
134141
old_len = len(self.dock.items["persistent-others"])
135142
self.dock.removeDockEntry("Application Support")
@@ -138,7 +145,7 @@ def test_remove_other(self):
138145
new_len = len(self.dock.items["persistent-others"])
139146
self.assertEqual(new_len, old_len - 1)
140147

141-
def test_add_url(self):
148+
def test_60_add_url(self):
142149
"""Ensure docklib can add url items to the dock."""
143150
item = self.dock.makeDockOtherURLEntry("https://www.apple.com", "Apple Inc")
144151
old_len = len(self.dock.items["persistent-others"])
@@ -148,7 +155,14 @@ def test_add_url(self):
148155
new_len = len(self.dock.items["persistent-others"])
149156
self.assertEqual(new_len, old_len + 1)
150157

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):
152166
"""Ensure docklib can remove url items from the dock."""
153167
old_len = len(self.dock.items["persistent-others"])
154168
self.dock.removeDockURLEntry("https://www.apple.com")
@@ -157,7 +171,7 @@ def test_remove_url(self):
157171
new_len = len(self.dock.items["persistent-others"])
158172
self.assertEqual(new_len, old_len - 1)
159173

160-
def test_add_spacer(self):
174+
def test_75_add_spacer(self):
161175
"""Ensure docklib can add a spacer item to the dock."""
162176
item = self.dock.makeDockAppSpacer()
163177
old_len = len(self.dock.items["persistent-apps"])
@@ -167,7 +181,7 @@ def test_add_spacer(self):
167181
new_len = len(self.dock.items["persistent-apps"])
168182
self.assertEqual(new_len, old_len + 1)
169183

170-
def test_remove_spacer(self):
184+
def test_80_remove_spacer(self):
171185
"""Ensure docklib can remove a spacer item from the dock."""
172186
old_len = len(self.dock.items["persistent-apps"])
173187
del self.dock.items["persistent-apps"][0]

0 commit comments

Comments
 (0)