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_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 setUp(self): self.DEP_INFO = { 'dep1': { 'installed_version': '2.1.0', 'installed_version_time': '2018-05-12T16:26:31', 'latest_version': '2.1.0', 'current_time': '2018-08-27T17:04:57.260105', 'latest_version_time': '2018-05-12T16:26:31', 'is_latest': True, }, 'dep2': { 'installed_version': '3.6.1', 'installed_version_time': '2018-08-13T22:47:09', 'latest_version': '3.6.1', 'current_time': '2018-08-27T17:04:57.934866', 'latest_version_time': '2018-08-13T22:47:09', 'is_latest': True, }, } self.SELF_COMP_RES = (( { 'result': 'SUCCESS', 'packages': ['package1'], 'description': None, 'dependency_info': self.DEP_INFO, }, ),) self.mock_checker = mock.Mock(autospec=True) self.fake_store = fake_compatibility_store.CompatibilityStore() self.mock_checker.get_self_compatibility.return_value = \ self.SELF_COMP_RES
def setUp(self): self.mock_checker = mock.Mock(autospec=True) self.fake_store = fake_compatibility_store.CompatibilityStore() self.patch_checker = mock.patch('main.badge_utils.checker', self.mock_checker) self.patch_store = mock.patch('main.badge_utils.store', self.fake_store)
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_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. """ 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: grid = grid_builder.GridBuilder(store) html_grid = grid.build_grid([PACKAGE_1, PACKAGE_2]) self.assertNotIn("Installation failure", html_grid)
def test_missing_self(self): """CompatibilityResult not available for individual packages.""" store = fake_compatibility_store.CompatibilityStore() store.save_compatibility_statuses([ compatibility_store.CompatibilityResult( packages=[PACKAGE_1, PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS), ]) grid = grid_builder.GridBuilder(store) grid.build_grid([PACKAGE_1, PACKAGE_2])
def test_self_failure(self): """CompatibilityResult failure installing a single package.""" 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="Installation failure"), compatibility_store.CompatibilityResult( packages=[PACKAGE_2], python_major_version=3, status=compatibility_store.Status.SUCCESS), ]) grid = grid_builder.GridBuilder(store) html_grid = grid.build_grid([PACKAGE_1, PACKAGE_2]) self.assertIn("Installation failure", html_grid)
def setUp(self): self.mock_checker = mock.Mock() self.mock_checker.get_compatibility.return_value = self.results self.fake_store = fake_compatibility_store.CompatibilityStore() def mock_init(): return None self.patch_constructor = mock.patch.object( compatibility_store.CompatibilityStore, '__init__', side_effect=mock_init) self.patch_checker = mock.patch( 'compatibility_lib.get_compatibility_data.checker', self.mock_checker) self.patch_store = mock.patch( 'compatibility_lib.get_compatibility_data.store', self.fake_store)
def test_success(self): """CompatibilityResult available for all packages and pairs.""" 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), ]) grid = grid_builder.GridBuilder(store) grid.build_grid([PACKAGE_1, PACKAGE_2])
def setUp(self): self.fake_store = fake_compatibility_store.CompatibilityStore() self.dependency_highlighter_stub = dependency_highlighter_stub.DependencyHighlighterStub( ) self.deprecated_dep_finder_stub = deprecated_dep_finder_stub.DeprecatedDepFinderStub( ) main.app.config['TESTING'] = True self.client = main.app.test_client() self._store_patch = unittest.mock.patch('utils.store', self.fake_store) self._highlighter_patch = unittest.mock.patch( 'utils.highlighter', self.dependency_highlighter_stub) self._finder_patch = unittest.mock.patch( 'utils.finder', self.deprecated_dep_finder_stub) self._pkg_list_patch = unittest.mock.patch( 'compatibility_lib.configs.PKG_LIST', [ 'apache-beam[gcp]', 'google-api-core', 'google-api-python-client', 'tensorflow', ]) self._whitelist_urls_patch = unittest.mock.patch( 'compatibility_lib.configs.WHITELIST_URLS', { 'git+git://github.com/google/apache-beam.git': 'apache-beam[gcp]', 'git+git://github.com/google/api-core.git': 'google-api-core', 'git+git://github.com/google/api-python-client.git': 'google-api-python-client', 'git+git://github.com/google/tensorflow.git': 'tensorflow', }) self._store_patch.start() self.addCleanup(self._store_patch.stop) self._highlighter_patch.start() self.addCleanup(self._highlighter_patch.stop) self._finder_patch.start() self.addCleanup(self._finder_patch.stop) self._pkg_list_patch.start() self.addCleanup(self._pkg_list_patch.stop) self._whitelist_urls_patch.start() self.addCleanup(self._whitelist_urls_patch.stop)
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 setUp(self): self._store = fake_compatibility_store.CompatibilityStore()
def setUp(self): self.mock_checker = MockChecker() self.fake_store = fake_compatibility_store.CompatibilityStore()