Skip to content

Commit 140cec7

Browse files
committed
tests: Use a class attribute to store the test mode
1 parent e86e945 commit 140cec7

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

usr/lib/linuxmint/mintUpdate/mintUpdate.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def __init__(self):
190190
self.logger = logger.Logger()
191191
self.cache_monitor = None
192192
self.logger.write("Launching Update Manager")
193+
self.test_mode = os.getenv("MINTUPDATE_TEST")
193194
self.settings = Gio.Settings(schema_id="com.linuxmint.updates")
194195

195196
self.is_lmde = False
@@ -2150,30 +2151,27 @@ def dummy_update(self, check, package_name, kernel=False):
21502151

21512152
# Part of check_apt_in_external_process fork
21522153
def handle_apt_check_test(self, queue):
2153-
test_mode = os.getenv("MINTUPDATE_TEST")
2154-
if test_mode is None:
2155-
return False
2156-
2157-
if test_mode == "error":
2154+
print("SIMULATING TEST MODE:", self.test_mode)
2155+
if self.test_mode == "error":
21582156
# See how an error from checkAPT subprocess is handled
21592157
raise Exception("Testing - this is a simulated error.")
2160-
elif test_mode == "up-to-date":
2158+
elif self.test_mode == "up-to-date":
21612159
# Simulate checkAPT finding no updates
21622160
queue.put([None, []])
2163-
elif test_mode == "self-update":
2161+
elif self.test_mode == "self-update":
21642162
# Simulate an update of mintupdate itself.
21652163
check = checkAPT.APTCheck()
21662164
self.dummy_update(check, "mintupdate", False)
21672165
queue.put([None, list(check.updates.values())])
2168-
elif test_mode == "updates":
2166+
elif self.test_mode == "updates":
21692167
# Simulate some normal updates
21702168
check = checkAPT.APTCheck()
21712169
self.dummy_update(check, "python3", False)
21722170
self.dummy_update(check, "mint-meta-core", False)
21732171
self.dummy_update(check, "linux-generic", True)
21742172
self.dummy_update(check, "xreader", False)
21752173
queue.put([None, list(check.updates.values())])
2176-
elif test_mode == "tracker-max-age":
2174+
elif self.test_mode == "tracker-max-age":
21772175
# Simulate the UpdateTracker notifying about updates.
21782176
check = checkAPT.APTCheck()
21792177
self.dummy_update(check, "dnsmasq", False)
@@ -2203,17 +2201,17 @@ def handle_apt_check_test(self, queue):
22032201
def check_apt_in_external_process(self, queue):
22042202
# in the queue we put: error_message (None if successful), list_of_updates (None if error)
22052203
try:
2206-
if self.handle_apt_check_test(queue):
2207-
return
2208-
2209-
check = checkAPT.APTCheck()
2210-
check.find_changes()
2211-
check.apply_l10n_descriptions()
2212-
check.load_aliases()
2213-
check.apply_aliases()
2214-
check.clean_descriptions()
2215-
updates = check.get_updates()
2216-
queue.put([None, updates])
2204+
if self.test_mode:
2205+
self.handle_apt_check_test(queue)
2206+
else:
2207+
check = checkAPT.APTCheck()
2208+
check.find_changes()
2209+
check.apply_l10n_descriptions()
2210+
check.load_aliases()
2211+
check.apply_aliases()
2212+
check.clean_descriptions()
2213+
updates = check.get_updates()
2214+
queue.put([None, updates])
22172215
except Exception as error:
22182216
error_msg = str(error).replace("E:", "\n").strip()
22192217
queue.put([error_msg, None])
@@ -2228,7 +2226,7 @@ def refresh_updates(self):
22282226
time.sleep(1)
22292227

22302228
# Check presence of Mint layer
2231-
if os.getenv("MINTUPDATE_TEST") == "layer-error" or (not self.check_policy()):
2229+
if self.test_mode == "layer-error" or (not self.check_policy()):
22322230
error_msg = "%s\n%s\n%s" % (_("Your APT configuration is corrupt."),
22332231
_("Do not install or update anything - doing so could break your operating system!"),
22342232
_("To switch to a different Linux Mint mirror and solve this problem, click OK."))

0 commit comments

Comments
 (0)