def test_pypi_user(self, user_packages): user_packages.side_effect = lambda u: ['p1'] sys.argv = ['pep438', '-u', 'testuser'] with patch_io() as new: main() user_packages.assert_called_once_with('testuser') self.valid_package.assert_called_once_with('p1') self.get_urls.called_once_with('p1') self.assertEqual(new.stdout.getvalue(), "\u2713 p1: 0 URLs\n")
def test_valid_package(self, valid_package, get_links): valid_package.new_callable = lambda p: True get_links.new_callable = [] sys.argv = ['pep438', 'p1', 'p2'] with patch_io() as new: main() self.assertEqual(new.stderr.getvalue(), "") self.assertEqual(new.stdout.getvalue(), "\u2717 p1: 0 links\n\u2717 p2: 0 links\n")
def test_errors_only(self): sys.argv = ['pep438', '--errors-only', 'p1', 'p2'] self.get_urls.side_effect = lambda p: ['1', '2'] if p == 'p1' else [] with patch_io() as new: main() self.assertEqual(self.valid_package.call_count, 2) self.assertEqual(self.get_urls.call_count, 2) self.assertEqual(new.stderr.getvalue(), "") self.assertEqual(new.stdout.getvalue(), "\u2717 p1: 2 URLs\n")
def test_valid_package(self): sys.argv = ['pep438', 'p1', 'p2'] with patch_io() as new: main() self.assertEqual(self.valid_package.call_count, 2) self.assertEqual(self.get_urls.call_count, 2) self.assertEqual(new.stderr.getvalue(), "") self.assertEqual(new.stdout.getvalue(), "\u2713 p1: 0 URLs\n\u2713 p2: 0 URLs\n")
def test_invalid_package(self, valid_package, get_links): valid_package.side_effect = lambda p: p != 'invalid' get_links.new_callable = [] sys.argv = ['pep438', 'valid', 'invalid'] with patch_io() as new: main() self.assertEqual(new.stderr.getvalue(), "\u2717 invalid: not found on PyPI\n") self.assertEqual(new.stdout.getvalue(), "\u2717 valid: 0 links\n")
def test_invalid_package(self): self.valid_package.side_effect = lambda p: p != 'invalid' sys.argv = ['pep438', 'valid', 'invalid'] with patch_io() as new: main() self.assertEqual(self.valid_package.call_count, 2) self.assertEqual(self.get_urls.call_count, 1) self.assertEqual(new.stderr.getvalue(), "\u26a0 invalid: not found on PyPI\n") self.assertEqual(new.stdout.getvalue(), "\u2713 valid: 0 URLs\n")
def test_stdin(self): sys.argv = ['pep438'] with patch_io() as new: new.stdin.write('p1\np2\n') new.stdin.seek(0) main() self.assertEqual(self.valid_package.call_count, 2) self.assertEqual(self.get_urls.call_count, 2) self.assertEqual(new.stderr.getvalue(), "") self.assertEqual(new.stdout.getvalue(), "\u2713 p1: 0 URLs\n\u2713 p2: 0 URLs\n")
#!/usr/bin/env python from pep438.main import main if __name__ == "__main__": main()