示例#1
0
    def test_version_attribute(self, attribute, expected_modules, import_fake):
        """Test with a different version attribute.

        VERSION is tested for old colorama versions, and None to make sure
        things still work if some package suddenly doesn't have __version__.

        Args:
            attribute: The name of the version attribute.
            expected: The expected return value.
        """
        import_fake.version_attribute = attribute

        for mod_info in version.MODULE_INFO.values():
            # Invalidate the "version cache" since we just mocked some of the
            # attributes.
            mod_info._reset_cache()

        expected = []
        for name in import_fake.modules:
            mod_info = version.MODULE_INFO[name]
            if name in expected_modules:
                assert mod_info.get_version() == "1.2.3"
                expected.append('{}: 1.2.3'.format(name))
            else:
                assert mod_info.get_version() is None
                expected.append('{}: yes'.format(name))

        assert version._module_versions() == expected
示例#2
0
    def test_missing_module(self, module, idx, expected, import_fake):
        """Test with a module missing.

        Args:
            module: The name of the missing module.
            idx: The index where the given text is expected.
            expected: The expected text.
        """
        import_fake.modules[module] = False
        # Needed after mocking the module
        mod_info = version.MODULE_INFO[module]
        mod_info._reset_cache()

        assert version._module_versions()[idx] == expected

        for method_name, expected_result in [
            ("is_installed", False),
            ("is_usable", False),
            ("get_version", None),
            ("is_outdated", None)
        ]:
            method = getattr(mod_info, method_name)
            # With hot cache
            mod_info._initialize_info()
            assert method() == expected_result
            # With cold cache
            mod_info._reset_cache()
            assert method() == expected_result
示例#3
0
 def test_all_present(self):
     """Test with all modules present in version 1.2.3."""
     expected = [
         'sip: yes', 'colorama: 1.2.3', 'pypeg2: 1.2.3', 'jinja2: 1.2.3',
         'pygments: 1.2.3', 'yaml: 1.2.3', 'cssutils: 1.2.3', 'typing: yes'
     ]
     assert version._module_versions() == expected
示例#4
0
 def test_all_present(self):
     """Test with all modules present in version 1.2.3."""
     expected = ['sip: yes', 'colorama: 1.2.3', 'pypeg2: 1.2.3',
                 'jinja2: 1.2.3', 'pygments: 1.2.3', 'yaml: 1.2.3',
                 'cssutils: 1.2.3', 'typing: yes',
                 'PyQt5.QtWebEngineWidgets: yes']
     assert version._module_versions() == expected
示例#5
0
 def test_all_present(self, import_fake):
     """Test with all modules present in version 1.2.3."""
     expected = []
     for name in import_fake.modules:
         if name in import_fake.no_version_attribute:
             expected.append('{}: yes'.format(name))
         else:
             expected.append('{}: 1.2.3'.format(name))
     assert version._module_versions() == expected
示例#6
0
 def test_all_present(self, import_fake):
     """Test with all modules present in version 1.2.3."""
     expected = []
     for name in import_fake.modules:
         if name in import_fake.no_version_attribute:
             expected.append('{}: yes'.format(name))
         else:
             expected.append('{}: 1.2.3'.format(name))
     assert version._module_versions() == expected
示例#7
0
 def test_all_present(self, import_fake):
     """Test with all modules present in version 1.2.3."""
     expected = []
     for name in import_fake.modules:
         version.MODULE_INFO[name]._reset_cache()
         if '__version__' not in version.MODULE_INFO[name]._version_attributes:
             expected.append('{}: yes'.format(name))
         else:
             expected.append('{}: 1.2.3'.format(name))
     assert version._module_versions() == expected
示例#8
0
    def test_missing_module(self, module, idx, expected, import_fake):
        """Test with a module missing.

        Args:
            module: The name of the missing module.
            idx: The index where the given text is expected.
            expected: The expected text.
        """
        import_fake.exists[module] = False
        assert version._module_versions()[idx] == expected
示例#9
0
    def test_missing_module(self, module, idx, expected, import_fake):
        """Test with a module missing.

        Args:
            module: The name of the missing module.
            idx: The index where the given text is expected.
            expected: The expected text.
        """
        import_fake.exists[module] = False
        assert version._module_versions()[idx] == expected
示例#10
0
    def test_version_attribute(self, value, expected, import_fake):
        """Test with a different version attribute.

        VERSION is tested for old colorama versions, and None to make sure
        things still work if some package suddenly doesn't have __version__.

        Args:
            value: The name of the version attribute.
            expected: The expected return value.
        """
        import_fake.version_attribute = value
        assert version._module_versions() == expected
示例#11
0
    def test_version_attribute(self, value, expected, import_fake):
        """Test with a different version attribute.

        VERSION is tested for old colorama versions, and None to make sure
        things still work if some package suddenly doesn't have __version__.

        Args:
            value: The name of the version attribute.
            expected: The expected return value.
        """
        import_fake.version_attribute = value
        assert version._module_versions() == expected
示例#12
0
 def test_all_present(self):
     """Test with all modules present in version 1.2.3."""
     expected = [
         "sip: yes",
         "colorlog: yes",
         "colorama: 1.2.3",
         "pypeg2: 1.2.3",
         "jinja2: 1.2.3",
         "pygments: 1.2.3",
         "yaml: 1.2.3",
     ]
     assert version._module_versions() == expected
示例#13
0
    def test_outdated_adblock(self, import_fake):
        """Test that warning is shown when adblock module is outdated."""
        mod_info = version.MODULE_INFO["adblock"]
        fake_version = "0.1.0"

        # Needed after mocking version attribute
        mod_info._reset_cache()

        assert mod_info.min_version is not None
        assert fake_version < mod_info.min_version
        import_fake.version = fake_version

        assert mod_info.is_installed()
        assert mod_info.is_outdated()
        assert not mod_info.is_usable()

        expected = f"adblock: {fake_version} (< {mod_info.min_version}, outdated)"
        assert version._module_versions()[5] == expected
示例#14
0
    def test_version_attribute(self, attribute, expected_modules, import_fake):
        """Test with a different version attribute.

        VERSION is tested for old colorama versions, and None to make sure
        things still work if some package suddenly doesn't have __version__.

        Args:
            attribute: The name of the version attribute.
            expected: The expected return value.
        """
        import_fake.version_attribute = attribute
        expected = []
        for name in import_fake.modules:
            if name in expected_modules:
                expected.append('{}: 1.2.3'.format(name))
            else:
                expected.append('{}: yes'.format(name))
        assert version._module_versions() == expected
示例#15
0
    def test_version_attribute(self, attribute, expected_modules, import_fake):
        """Test with a different version attribute.

        VERSION is tested for old colorama versions, and None to make sure
        things still work if some package suddenly doesn't have __version__.

        Args:
            attribute: The name of the version attribute.
            expected: The expected return value.
        """
        import_fake.version_attribute = attribute
        expected = []
        for name in import_fake.modules:
            if name in expected_modules:
                expected.append('{}: 1.2.3'.format(name))
            else:
                expected.append('{}: yes'.format(name))
        assert version._module_versions() == expected
示例#16
0
 def test_all_present(self):
     """Test with all modules present in version 1.2.3."""
     expected = ['sip: yes', 'colorlog: yes', 'colorama: 1.2.3',
                 'pypeg2: 1.2.3', 'jinja2: 1.2.3', 'pygments: 1.2.3',
                 'yaml: 1.2.3']
     assert version._module_versions() == expected