def test_get_deprecated_dep(self): # TODO: use a more convincing mock that doesn't say that *all* packages # are deprecated. mock_call_pypi_json_api = mock.Mock(autospec=True) mock_call_pypi_json_api.return_value = self.PKG_INFO self.fake_store.save_compatibility_statuses([ compatibility_store.CompatibilityResult( packages=[package.Package('opencencus')], python_major_version='3', status=compatibility_store.Status.SUCCESS, details=None, dependency_info=self.DEP_INFO), ]) patch_utils = mock.patch( 'compatibility_lib.deprecated_dep_finder.utils.call_pypi_json_api', mock_call_pypi_json_api) with patch_utils: finder = deprecated_dep_finder.DeprecatedDepFinder( checker=self.mock_checker, store=self.fake_store) deprecated_deps = finder.get_deprecated_dep('opencencus') expected_deprecated_deps = set(['dep1', 'dep2']) self.assertEqual(set(deprecated_deps[1]), expected_deprecated_deps)
def test_constructor_explicit(self): from compatibility_lib import utils finder = deprecated_dep_finder.DeprecatedDepFinder( py_version='2', checker=self.mock_checker, store=self.fake_store) self.assertEqual(finder.py_version, '2') self.assertIsInstance(finder._dependency_info_getter, utils.DependencyInfo)
def test_constructor_default(self): from compatibility_lib import utils finder = deprecated_dep_finder.DeprecatedDepFinder( checker=self.mock_checker, store=self.fake_store) self.assertEqual(finder.py_version, '3') self.assertTrue( isinstance(finder._dependency_info_getter, utils.DependencyInfo))
def get_deprecated_deps(self) -> Mapping[str, List]: """ Returns if there are deprecated dependencies for a given package as well as the list of deprecated deps for a package. """ finder = deprecated_dep_finder.DeprecatedDepFinder( py_version='3', checker=self.checker, store=self.store) deprecated_deps = list(finder.get_deprecated_deps()) results = {} for item in deprecated_deps: (pkg_name, deps) = item[0] results[pkg_name] = deps return results
def test_get_deprecated_dep(self): mock_call_pypi_json_api = mock.Mock(autospec=True) mock_call_pypi_json_api.return_value = self.PKG_INFO patch_utils = mock.patch( 'compatibility_lib.deprecated_dep_finder.utils.call_pypi_json_api', mock_call_pypi_json_api) with patch_utils: finder = deprecated_dep_finder.DeprecatedDepFinder( checker=self.mock_checker, store=self.fake_store) deprecated_deps = finder.get_deprecated_dep('opencensus') expected_deprecated_deps = set(['dep1', 'dep2', 'dep3']) self.assertSetEqual(set(deprecated_deps[1]), expected_deprecated_deps)
def test__get_development_status_from_pypi(self): mock_call_pypi_json_api = mock.Mock(autospec=True) mock_call_pypi_json_api.return_value = self.PKG_INFO patch_utils = mock.patch( 'compatibility_lib.deprecated_dep_finder.utils.call_pypi_json_api', mock_call_pypi_json_api) with patch_utils: finder = deprecated_dep_finder.DeprecatedDepFinder( checker=self.mock_checker, store=self.fake_store) development_status = finder._get_development_status_from_pypi( 'package1') expected_development_status = "Development Status :: 7 - Inactive" self.assertEqual(development_status, expected_development_status)
def test__get_development_status_from_pypi_error(self): PKG_INFO = { 'test': { 'test_key_error': [], } } mock_call_pypi_json_api = mock.Mock(autospec=True) mock_call_pypi_json_api.return_value = PKG_INFO patch_utils = mock.patch( 'compatibility_lib.deprecated_dep_finder.utils.call_pypi_json_api', mock_call_pypi_json_api) with patch_utils: finder = deprecated_dep_finder.DeprecatedDepFinder( checker=self.mock_checker, store=self.fake_store) development_status = finder._get_development_status_from_pypi( 'package1') self.assertIsNone(development_status)
from compatibility_lib import compatibility_checker from compatibility_lib import compatibility_store from compatibility_lib import configs from compatibility_lib import dependency_highlighter from compatibility_lib import deprecated_dep_finder # Initializations DB_CONNECTION_NAME = 'python-compatibility-tools:us-central1:' \ 'compatibility-data' UNIX_SOCKET = '/cloudsql/{}'.format(DB_CONNECTION_NAME) checker = compatibility_checker.CompatibilityChecker() store = compatibility_store.CompatibilityStore(mysql_unix_socket=UNIX_SOCKET) highlighter = dependency_highlighter.DependencyHighlighter( checker=checker, store=store) finder = deprecated_dep_finder.DeprecatedDepFinder( checker=checker, store=store) priority_level = dependency_highlighter.PriorityLevel TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S" URL_PREFIX = 'https://img.shields.io/badge/' GITHUB_HEAD_NAME = 'github head' GITHUB_API = 'https://api.github.com/repos' GITHUB_CACHE_TIME = 1800 # seconds SVG_CONTENT_TYPE = 'image/svg+xml' EMPTY_DETAILS = 'NO DETAILS' PACKAGE_NOT_SUPPORTED = "The package is not supported by checker server." PY_VER_MAPPING = { 2: 'py2', 3: 'py3',