def test__get_missing_details_missing_inputs(self):
        from compatibility_lib import compatibility_store
        from compatibility_lib import package
        TENSORFLOW = 'tensorflow'
        TENSORFLOW_RESULT_PY2 = compatibility_store.CompatibilityResult(
            packages=[package.Package(TENSORFLOW)],
            python_major_version=2,
            status=compatibility_store.Status.SUCCESS)
        TENSORFLOW_RESULT_PY3 = compatibility_store.CompatibilityResult(
            packages=[package.Package(TENSORFLOW)],
            python_major_version=3,
            status=compatibility_store.Status.SUCCESS)

        with self.assertRaises(AssertionError):
            package_names = []
            results = []
            main._get_missing_details(package_names, results)

        with self.assertRaises(AssertionError):
            package_names = []
            results = [TENSORFLOW_RESULT_PY2]
            main._get_missing_details(package_names, results)

        with self.assertRaises(AssertionError):
            package_names = []
            results = [TENSORFLOW_RESULT_PY2, TENSORFLOW_RESULT_PY3]
            main._get_missing_details(package_names, results)
    def test__get_missing_details_unsupported_packages(self):
        from compatibility_lib import compatibility_store
        from compatibility_lib import package
        TENSORFLOW = 'tensorflow'
        UNSUPPORTED = 'unsupported'
        UNSUPPORTED_RESULT_PY2 = compatibility_store.CompatibilityResult(
            packages=[package.Package(UNSUPPORTED)],
            python_major_version=2,
            status=compatibility_store.Status.UNKNOWN)
        PAIR_RESULT_PY3 = compatibility_store.CompatibilityResult(
            packages=[package.Package(p) for p in (TENSORFLOW, UNSUPPORTED)],
            python_major_version=3,
            status=compatibility_store.Status.UNKNOWN)

        with self.assertRaises(AssertionError):
            package_names = [UNSUPPORTED]
            results = [UNSUPPORTED_RESULT_PY2]
            main._get_missing_details(package_names, results)

        with self.assertRaises(AssertionError):
            package_names = [TENSORFLOW, UNSUPPORTED]
            results = [PAIR_RESULT_PY3]
            main._get_missing_details(package_names, results)
 def test__get_missing_details_pair_fail(self):
     from compatibility_lib import compatibility_store
     from compatibility_lib import package
     package_names = ['opencensus', 'compatibility-lib']
     results = [
         compatibility_store.CompatibilityResult(
             packages=[package.Package(name) for name in package_names],
             python_major_version=2,
             status=compatibility_store.Status.SUCCESS)
     ]
     details = main._get_missing_details(package_names, results)
     expected_details = ("Missing data for packages=['opencensus', "
                         "'compatibility-lib'], versions=[3]")
     self.assertEqual(details, expected_details)
    def test__get_missing_details_self_fail(self):
        from compatibility_lib import compatibility_store
        expected = {
            'opencensus':
            "Missing data for packages=['opencensus'], versions=[2, 3]",
            'apache-beam[gcp]':
            "Missing data for packages=['apache-beam[gcp]'], versions=[2]",
            'tensorflow':
            "Missing data for packages=['tensorflow'], versions=[3]",
        }

        for name, expected_details in expected.items():
            package_names = [name]
            results = []
            details = main._get_missing_details(package_names, results)
            self.assertEqual(details, expected_details)
 def test__get_missing_details_for_self_compatibility(self):
     from compatibility_lib import compatibility_store
     from compatibility_lib import configs
     from compatibility_lib import package
     for package_name in configs.WHITELIST_PKGS:
         results = []
         if package_name not in ('tensorflow'):
             results.append(
                 compatibility_store.CompatibilityResult(
                     packages=[package.Package(p) for p in package_name],
                     python_major_version=2,
                     status=compatibility_store.Status.SUCCESS))
         if package_name not in ('apache-beam[gcp]', 'gsutil'):
             results.append(
                 compatibility_store.CompatibilityResult(
                     packages=[package.Package(p) for p in package_name],
                     python_major_version=3,
                     status=compatibility_store.Status.SUCCESS))
         details = main._get_missing_details([package_name], results)
         self.assertEqual(details, None)
 def test__get_missing_details_for_pair_compatibility(self):
     from compatibility_lib import compatibility_store
     from compatibility_lib import configs
     from compatibility_lib import package
     import itertools
     for p1, p2 in itertools.combinations(configs.WHITELIST_PKGS, r=2):
         pkgs = [p1, p2]
         results = []
         if all([p not in ('tensorflow') for p in pkgs]):
             results.append(
                 compatibility_store.CompatibilityResult(
                     packages=[package.Package(p) for p in pkgs],
                     python_major_version=2,
                     status=compatibility_store.Status.SUCCESS))
         if all([p not in ('apache-beam[gcp]', 'gsutil') for p in pkgs]):
             results.append(
                 compatibility_store.CompatibilityResult(
                     packages=[package.Package(p) for p in pkgs],
                     python_major_version=3,
                     status=compatibility_store.Status.SUCCESS))
         details = main._get_missing_details(pkgs, results)
         self.assertEqual(details, None)
 def test__get_missing_details_too_many_inputs(self):
     from compatibility_lib import compatibility_store
     with self.assertRaises(AssertionError):
         package_names = ['tensorflow', 'opencensus', 'compatibility-lib']
         results = []
         main._get_missing_details(package_names, results)