def test_version(self): """ Test to Common interface for obtaining the version of installed packages. """ with patch.object(salt.utils.data, "is_true", return_value=True): mock = MagicMock(return_value={"A": "B"}) with patch.dict(pkg_resource.__salt__, {"pkg.list_pkgs": mock}): self.assertEqual(pkg_resource.version("A"), "B") self.assertDictEqual(pkg_resource.version(), {}) mock = MagicMock(return_value={}) with patch.dict(pkg_resource.__salt__, {"pkg.list_pkgs": mock}): with patch("builtins.next") as mock_next: mock_next.side_effect = StopIteration() self.assertEqual(pkg_resource.version("A"), "")
def test_version(self): ''' Test to Common interface for obtaining the version of installed packages. ''' with patch.object(salt.utils, 'is_true', return_value=True): mock = MagicMock(return_value={'A': 'B'}) with patch.dict(pkg_resource.__salt__, {'pkg.list_pkgs': mock}): self.assertEqual(pkg_resource.version('A'), 'B') self.assertDictEqual(pkg_resource.version(), {}) mock = MagicMock(return_value={}) with patch.dict(pkg_resource.__salt__, {'pkg.list_pkgs': mock}): with patch('__builtin__.next') as mock_next: mock_next.side_effect = StopIteration() self.assertEqual(pkg_resource.version('A'), '')
def test_version(self): ''' Test to Common interface for obtaining the version of installed packages. ''' with patch.object(salt.utils, 'is_true', return_value=True): mock = MagicMock(return_value={'A': 'B'}) with patch.dict(pkg_resource.__salt__, {'pkg.list_pkgs': mock}): self.assertEqual(pkg_resource.version('A'), 'B') self.assertDictEqual(pkg_resource.version(), {}) mock = MagicMock(return_value={}) with patch.dict(pkg_resource.__salt__, {'pkg.list_pkgs': mock}): with patch('builtins.next' if six.PY3 else '__builtin__.next') as mock_next: mock_next.side_effect = StopIteration() self.assertEqual(pkg_resource.version('A'), '')