def setUp(self): self.output = io.StringIO() self.local_package_set = mock.create_autospec(pacman.LocalPackageSet) init_patch = mock.patch('pacfeed.feed.pacman.LocalPackageSet').start() self.addCleanup(mock.patch.stopall) init_patch.return_value = self.local_package_set self.handler = feed.OutputHandler(self.output) self.package = pacman.Package('foo', '1.2-3') self.pub_date = 'Tue, 19 Jan 2016 06:36:16 +0000'
def test_parse(self): handler = TestHandler() fake_response = open(path.dirname(__file__) + '/fixtures/rss.xml') with mock.patch('pacfeed.feed.urllib.request.urlopen') as open_patch,\ mock.patch('pacfeed.feed.get_repos') as get_repos_patch: get_repos_patch.return_value = ('Core', 'Extra') open_patch.return_value = fake_response feed.parse(handler) open_patch.assert_called_once_with(feed.FEED_URL) self.assertEqual(handler.packages, [ ( pacman.Package('libreoffice-fresh', '5.2.0-4'), 'Sun, 28 Aug 2016 19:56:03 +0000' ), ( pacman.Package('man-db', '2.7.5-4'), 'Sun, 28 Aug 2016 01:57:45 +0000' ), ])
def parse(handler): """Download packages feed and pass packages to the given handler. Args: handler: object to handle each package and pub_date """ repos = get_repos() with urllib.request.urlopen(FEED_URL) as response: rss = xml.etree.ElementTree.parse(response) for item in rss.iter('item'): if item.find('category').text in repos: name, version = item.find('title').text.split()[0:2] package = pacman.Package(name, version) pub_date = item.find('pubDate').text handler.handle(package, pub_date)
def test_handle_with_out_of_date_package(self): newer_package = pacman.Package('foo', '1.3-1') self._test_handle(newer_package, '\033[91mfoo')
def setUp(self): self.package = pacman.Package('python', '3.5.1-1')
def test_get_with_installed_package(self): self.assertEqual(self.local_package_set.get('linux'), pacman.Package('linux', '4.3.3-2'))
def test_eq_false(self): self.assertNotEqual(self.package, pacman.Package('python', '3.5.0-2')) self.assertNotEqual(self.package, pacman.Package('linux', '3.5.1-1'))
def test_eq_true(self): self.assertEqual(self.package, pacman.Package('python', '3.5.1-1'))