Skip to content

Commit

Permalink
More coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohn-msft committed Nov 7, 2024
1 parent 376de60 commit 9368e1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/core/src/package_managers/AptitudePackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import os
import re
import shutil
import sys

from core.src.package_managers.PackageManager import PackageManager
Expand Down Expand Up @@ -128,9 +129,7 @@ def __get_custom_sources_to_spec(self, max_patch_published_date=str(), base_clas
# Source parts debstyle882-only initialization
current_source_parts_deb882_style_file = os.path.join(self.current_source_parts_dir, self.current_source_parts_file_name)
if os.path.isdir(self.current_source_parts_dir):
if os.path.exists(current_source_parts_deb882_style_file):
os.remove(current_source_parts_deb882_style_file)
os.remove(self.current_source_parts_dir)
shutil.rmtree(self.current_source_parts_dir)

Check warning on line 132 in src/core/src/package_managers/AptitudePackageManager.py

View check run for this annotation

Codecov / codecov/patch

src/core/src/package_managers/AptitudePackageManager.py#L132

Added line #L132 was not covered by tests

# Create the folder and write to it only if there is debstyle882 content to be written
if len(source_parts_deb882_style_content) > 0:
Expand Down
15 changes: 11 additions & 4 deletions src/core/tests/Test_AptitudePackageManagerCustomSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ def setUp(self):
def tearDown(self):
self.runtime.stop()

def test_bad_custom_sources_to_spec_invocation(self):
package_manager = AptitudePackageManager.AptitudePackageManager(self.runtime.env_layer, self.runtime.execution_config, self.runtime.composite_logger, self.runtime.telemetry_writer, self.runtime.status_handler)
sources_dir, sources_list = package_manager._AptitudePackageManager__get_custom_sources_to_spec(base_classification="other") # invalid call
self.assertEqual(sources_list, str())
self.assertEqual(sources_dir, str())

def test_sources_list_and_parts_combinations(self):
# type: () -> None
# Tests 32 combinations of source configuration on disk and desired manipulations + caching
for include_sources_list in [True, False]:
for include_source_parts_list in [True, False]:
Expand Down Expand Up @@ -64,7 +69,7 @@ def __lib_test_custom_sources_with(self, include_sources_list=False, include_sou
for i in range(3):
# All
expected_debstyle_entry_count = 2 if include_source_parts_debstyle else 0 # 2 entries in the debstyle mock
expected_sources_list_entry_count = (4 if include_sources_list else 0) + (3 if include_source_parts_list else 0) # 4 in regular file, 3 in mock folder
expected_sources_list_entry_count = (4 if include_sources_list else 0) + (5 if include_source_parts_list else 0) # 4 in regular file, 3 in mock folder
sources_dir, sources_list = package_manager._AptitudePackageManager__get_custom_sources_to_spec(include_max_patch_publish_date)
self.__check_custom_sources(sources_dir, sources_list,
sources_debstyle_expected=include_source_parts_debstyle,
Expand Down Expand Up @@ -124,7 +129,7 @@ def __check_custom_sources(self, sources_dir, sources_list, sources_debstyle_exp
for entry in data:
if security_only:
self.assertTrue("security" in entry)
if max_patch_publish_date != str():
if max_patch_publish_date != str() and "ppa" not in entry: # exception for unsupported repo
self.assertTrue(max_patch_publish_date in entry)

# region - Mock sources preparation and clean up
Expand Down Expand Up @@ -173,8 +178,10 @@ def __get_sources_data_one_line_style_def():
@staticmethod
def __get_sources_data_one_line_style_ext():
return "deb http://us.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse\n" + \
"deb http://ppa.launchpad.net/upubuntu-com/web/ubuntu focal main\n" + \
"deb http://azure.archive.ubuntu.com/ubuntu/ focal-security universe\n" + \
"deb http://in.archive.ubuntu.com/ubuntu/ focal multiverse\n"
"deb http://in.archive.ubuntu.com/ubuntu/ focal multiverse\n" + \
"deb http://cn.archive.ubuntu.com/ubuntu/ focal main\n"

@staticmethod
def __get_sources_data_debstyle():
Expand Down

0 comments on commit 9368e1e

Please sign in to comment.