def test_pairwise_failure(self): """CompatibilityResult failure between pair of packages.""" packages = [PACKAGE_1, PACKAGE_2] store = fake_compatibility_store.CompatibilityStore() store.save_compatibility_statuses([ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS), compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS), compatibility_store.CompatibilityResult( packages=[PACKAGE_1, PACKAGE_2], python_major_version=3, status=compatibility_store.Status.INSTALL_ERROR, details="Installation failure"), ]) with self.patch_finder, self.patch_highlighter: package_to_results = store.get_self_compatibilities(packages) pairwise_to_results = store.get_compatibility_combinations( packages) results = dashboard_builder._ResultHolder(package_to_results, pairwise_to_results) builder = dashboard_builder.DashboardBuilder(packages, results) html_grid = builder.build_dashboard('dashboard/grid-template.html') self.assertIn("Installation failure", html_grid)
def test_self_compatibility_error(self): package_to_results = { PACKAGE_1: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.INSTALL_ERROR, details='Installation failure', ) ] } with self.patch_finder, self.patch_highlighter: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results={}) expected = { 'status_type': 'self-install_error', 'self_compatibility_check': [ { 'status': 'INSTALL_ERROR', 'self': True, 'details': 'Installation failure' }, { 'status': 'INSTALL_ERROR', 'self': True, 'details': 'Installation failure' }, ], 'pairwise_compatibility_check': [] } self.assertEqual(rh.get_result(PACKAGE_1, PACKAGE_1), expected)
def test_pairwise_issues(self): package_to_results = { PACKAGE_1: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ], PACKAGE_2: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ] } pairwise_to_results = { frozenset([PACKAGE_1, PACKAGE_2]): [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1, PACKAGE_2], python_major_version=3, status=compatibility_store.Status.INSTALL_ERROR, details='Installation failure', ) ] } with self.patch_finder, self.patch_highlighter: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results=pairwise_to_results) self.assertTrue(rh.has_issues(PACKAGE_1)) self.assertTrue(rh.has_issues(PACKAGE_2))
def test_success(self): """CompatibilityResult available for all packages and pairs.""" packages = [PACKAGE_1, PACKAGE_2] store = fake_compatibility_store.CompatibilityStore() store.save_compatibility_statuses([ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS), compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS), compatibility_store.CompatibilityResult( packages=[PACKAGE_1, PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS), ]) with self.patch_finder, self.patch_highlighter: package_to_results = store.get_self_compatibilities(packages) pairwise_to_results = store.get_compatibility_combinations( packages) results = dashboard_builder._ResultHolder(package_to_results, pairwise_to_results) builder = dashboard_builder.DashboardBuilder(packages, results) builder.build_dashboard('dashboard/grid-template.html')
def test_self_issues(self): package_to_results = { PACKAGE_1: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.CHECK_WARNING, details='Self Conflict', ) ], PACKAGE_2: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ], } pairwise_to_results = { frozenset([PACKAGE_1, PACKAGE_2]): [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1, PACKAGE_2], python_major_version=3, status=compatibility_store.Status.CHECK_WARNING, details='Conflict', ) ], } with self.patch_finder, self.patch_highlighter: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results=pairwise_to_results) self.assertTrue(rh.has_issues(PACKAGE_1)) self.assertFalse(rh.has_issues(PACKAGE_2))
def test_pairwise_no_entry(self): package_to_results = { PACKAGE_1: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ], PACKAGE_2: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ] } pairwise_to_results = {frozenset([PACKAGE_1, PACKAGE_2]): []} with self.patch_finder, self.patch_highlighter: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results=pairwise_to_results) expected = { 'status_type': 'pairwise-unknown', 'self_compatibility_check': [], 'pairwise_compatibility_check': [{ 'status': 'UNKNOWN', 'self': False }] } self.assertEqual(rh.get_result(PACKAGE_1, PACKAGE_2), expected)
def test_escape(self): """Test that the arguments to showDialog() are escaped.""" packages = [PACKAGE_1, PACKAGE_2] store = fake_compatibility_store.CompatibilityStore() store.save_compatibility_statuses([ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.INSTALL_ERROR, details=r"This \ has a ' in it < >"), compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS), ]) with self.patch_finder, self.patch_highlighter: package_to_results = store.get_self_compatibilities(packages) pairwise_to_results = store.get_compatibility_combinations( packages) results = dashboard_builder._ResultHolder(package_to_results, pairwise_to_results) builder = dashboard_builder.DashboardBuilder(packages, results) html_grid = builder.build_dashboard('dashboard/grid-template.html') with open('/tmp/foo.html', 'w+') as f: f.write(html_grid) self.assertIn("This \\\\ has a \\' in it < >", html_grid)
def test_get_package_details(self): package_with_dependency_info = { 'package1': { 'dep1': { 'latest_version': '0.0.1', }, 'package1': { 'latest_version': '1.2.0', } } } package_to_results = { PACKAGE_1: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ], PACKAGE_2: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ] } pairwise_to_results = {frozenset([PACKAGE_1, PACKAGE_2]): []} patch_pkg_list = mock.patch('dashboard_builder.configs.PKG_LIST', ['package1', 'package2']) with self.patch_finder, self.patch_highlighter, patch_pkg_list: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results=pairwise_to_results, package_with_dependency_info=package_with_dependency_info) result = rh.get_package_details(PACKAGE_1) expected = { 'self_conflict': False, 'pairwise_conflict': ['package2'], 'latest_version': '1.2.0' } self.assertEqual(result, expected)
def test_self_compatibility_no_entry(self): package_to_results = {PACKAGE_1: []} with self.patch_finder, self.patch_highlighter: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results={}) expected = { 'status_type': 'self-unknown', 'self_compatibility_check': [ { 'status': 'UNKNOWN', 'self': True }, ], 'pairwise_compatibility_check': [] } self.assertEqual(rh.get_result(PACKAGE_1, PACKAGE_1), expected)
def test_not_show_py_ver_incompatible_results(self): """CompatibilityResult failure between pair of packages. Do not display the packages that are incompatible with a specific Python version. """ packages = [PACKAGE_1, PACKAGE_2] store = fake_compatibility_store.CompatibilityStore() store.save_compatibility_statuses([ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS), compatibility_store.CompatibilityResult( packages=[PACKAGE_3], python_major_version=3, status=compatibility_store.Status.INSTALL_ERROR), compatibility_store.CompatibilityResult( packages=[PACKAGE_1, PACKAGE_3], python_major_version=3, status=compatibility_store.Status.INSTALL_ERROR, details="Installation failure"), ]) patch = mock.patch( 'compatibility_lib.configs.PKG_PY_VERSION_NOT_SUPPORTED', { 2: ['package4'], 3: ['package3'], }) with patch, self.patch_finder, self.patch_highlighter: package_to_results = store.get_self_compatibilities(packages) pairwise_to_results = store.get_compatibility_combinations( packages) results = dashboard_builder._ResultHolder(package_to_results, pairwise_to_results) builder = dashboard_builder.DashboardBuilder(packages, results) html_grid = builder.build_dashboard('dashboard/grid-template.html') self.assertNotIn("Installation failure", html_grid)
def test_self_compatibility_success(self): package_to_results = { PACKAGE_1: [ compatibility_store.CompatibilityResult( packages=[PACKAGE_1], python_major_version=3, status=compatibility_store.Status.SUCCESS, ) ] } with self.patch_finder, self.patch_highlighter: rh = dashboard_builder._ResultHolder( package_to_results=package_to_results, pairwise_to_results={}) expected = { 'status_type': 'self-success', 'self_compatibility_check': [{ 'status': 'SUCCESS', 'self': True }], 'pairwise_compatibility_check': [] } self.assertEqual(rh.get_result(PACKAGE_1, PACKAGE_1), expected)