def test_run_without_specific_version(self, murlopen): def mocked_get(url, **options): if url == 'https://pypi.org/pypi/hashin/json': return _Response({ 'info': { 'version': '0.10', 'name': 'hashin', }, 'releases': { '0.10': [ { 'url': 'https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl', 'digests': { 'sha256': 'aaaaa', }, }, { 'url': 'https://pypi.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl', 'digests': { 'sha256': 'bbbbb', }, }, { 'url': 'https://pypi.org/packages/source/p/hashin/hashin-0.10.tar.gz', 'digests': { 'sha256': 'ccccc', }, } ] } }) raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') retcode = hashin.run( 'hashin', filename, 'sha256', verbose=True ) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() self.assertTrue(output.startswith('hashin==0.10'))
def test_run(self, murlopen): def mocked_get(url, **options): if url == "https://pypi.python.org/pypi/hashin/json": return _Response({ 'info': { 'version': '0.10', }, 'releases': { '0.10': [ { 'url': 'https://pypi.python.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl', }, { 'url': 'https://pypi.python.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl', }, { 'url': 'https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz', } ] } }) elif url == "https://pypi.python.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl": return _Response(b"Some py2 wheel content\n") elif url == "https://pypi.python.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl": return _Response(b"Some py3 wheel content\n") elif url == "https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz": return _Response(b"Some tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run( 'hashin==0.10', filename, 'sha256', verbose=True ) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual( lines[0], 'hashin==0.10 \\' ) self.assertEqual( lines[1], ' --hash=sha256:31104f8c0f9816a6d2135db4232cfa248b2c' '7525596263216577d3cdc93a3c25 \\' ) self.assertEqual( lines[2], ' --hash=sha256:61fb59231ffe967ce693a2099cff59a2695e' '6d02acbb6b051033e3b1107d8008 \\' ) self.assertEqual( lines[3], ' --hash=sha256:b2f06d3c4d148b648768abab5086afac0414' 'e49eb4813e1f3c450b975c77cee9' ) # Now check the verbose output out_lines = my_stdout.getvalue().splitlines() self.assertTrue( 'https://pypi.python.org/pypi/hashin/json' in out_lines[0], out_lines[0] ) # url to download self.assertTrue( 'hashin-0.10-py2-none-any.whl' in out_lines[1], out_lines[1] ) # file it got downloaded to self.assertTrue( 'hashin-0.10-py2-none-any.whl' in out_lines[2], out_lines[2] ) # hash it got self.assertTrue( '31104f8c0f9816a6d2135db4232cfa248b2c7525596263216577d3cdc' '93a3c25' in out_lines[3], out_lines[3] ) # Change algorithm retcode = hashin.run('hashin==0.10', filename, 'sha512') self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual( lines[0], 'hashin==0.10 \\' ) self.assertEqual( lines[1], ' --hash=sha512:45d1c5d2237a3b4f78b4198709fb2ecf1f781c823' '4ce3d94356f2100a36739433952c6c13b2843952f608949e6baa9f95055' 'a314487cd8fb3f9d76522d8edb50 \\' ) self.assertEqual( lines[2], ' --hash=sha512:0d63bf4c115154781846ecf573049324f06b021a1' 'd4b92da4fae2bf491da2b83a13096b14d73e73cefad36855f4fa936bac4' 'b2357dabf05a2b1e7329ff1e5455 \\' ) self.assertEqual( lines[3], ' --hash=sha512:c32e6d9fb09dc36ab9222c4606a1f43a2dcc183a8' 'c64bdd9199421ef779072c174fa044b155babb12860cf000e36bc4d3586' '94fa22420c997b1dd75b623d4daa' )
def test_run_pep_0496(self, murlopen): """ Properly pass through specifiers which look like: enum==1.1.6; python_version <= '3.4' These can include many things besides python_version; see https://www.python.org/dev/peps/pep-0496/ """ def mocked_get(url, **options): if url == "https://pypi.python.org/pypi/enum34/json": return _Response({ 'info': { 'version': '1.1.6', 'name': 'enum34', }, 'releases': { "1.1.6": [{ "has_sig": False, "upload_time": "2016-05-16T03:31:13", "comment_text": "", "python_version": "py2", "url": "https://pypi.python.org/packages/c5/db/enum34-1.1.6-py2-none-any.whl", "md5_digest": "68f6982cc07dde78f4b500db829860bd", "downloads": 4297423, "filename": "enum34-1.1.6-py2-none-any.whl", "packagetype": "bdist_wheel", "path": "c5/db/enum34-1.1.6-py2-none-any.whl", "size": 12427 }, { "has_sig": False, "upload_time": "2016-05-16T03:31:19", "comment_text": "", "python_version": "py3", "url": "https://pypi.python.org/packages/af/42/enum34-1.1.6-py3-none-any.whl", "md5_digest": "a63ecb4f0b1b85fb69be64bdea999b43", "downloads": 98598, "filename": "enum34-1.1.6-py3-none-any.whl", "packagetype": "bdist_wheel", "path": "af/42/enum34-1.1.6-py3-none-any.whl", "size": 12428 }, { "has_sig": False, "upload_time": "2016-05-16T03:31:30", "comment_text": "", "python_version": "source", "url": "https://pypi.python.org/packages/bf/3e/enum34-1.1.6.tar.gz", "md5_digest": "5f13a0841a61f7fc295c514490d120d0", "downloads": 188090, "filename": "enum34-1.1.6.tar.gz", "packagetype": "sdist", "path": "bf/3e/enum34-1.1.6.tar.gz", "size": 40048 }, { "has_sig": False, "upload_time": "2016-05-16T03:31:48", "comment_text": "", "python_version": "source", "url": "https://pypi.python.org/packages/e8/26/enum34-1.1.6.zip", "md5_digest": "61ad7871532d4ce2d77fac2579237a9e", "downloads": 775920, "filename": "enum34-1.1.6.zip", "packagetype": "sdist", "path": "e8/26/enum34-1.1.6.zip", "size": 44773 }] } }) elif url.startswith("https://pypi.python.org/packages"): return _Response(b"Some tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run("enum34==1.1.6; python_version <= '3.4'", filename, 'sha256', verbose=True) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], "enum34==1.1.6; python_version <= '3.4' \\")
def test_run_case_insensitive(self, murlopen): """No matter how you run the cli with a package's case typing, it should find it and correct the cast typing per what it is inside the PyPI data.""" def mocked_get(url, **options): if url == "https://pypi.python.org/pypi/HAShin/json": return _Response({ 'info': { 'version': '0.10', 'name': 'hashin', }, 'releases': { '0.10': [{ 'url': 'https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz', }] } }) elif url == "https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz": return _Response(b"Some tarball content\n") elif url == "https://pypi.python.org/pypi/hashIN/json": return _Response({ 'info': { 'version': '0.11', 'name': 'hashin', }, 'releases': { '0.11': [{ 'url': 'https://pypi.python.org/packages/source/p/hashin/hashin-0.11.tar.gz', }] } }) elif url == "https://pypi.python.org/packages/source/p/hashin/hashin-0.11.tar.gz": return _Response(b"Some different tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run('HAShin==0.10', filename, 'sha256', verbose=True) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], 'hashin==0.10 \\') # Change version retcode = hashin.run('hashIN==0.11', filename, 'sha256') self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], 'hashin==0.11 \\')
def test_run_contained_names(self, murlopen): """ This is based on https://github.com/peterbe/hashin/issues/35 which was a real bug discovered in hashin 0.8.0. It happens because the second package's name is entirely contained in the first package's name. """ def mocked_get(url, **options): if url == "https://pypi.python.org/pypi/django-redis/json": return _Response({ 'info': { 'version': '4.7.0', 'name': 'django-redis', }, 'releases': { '4.7.0': [{ 'url': 'https://pypi.python.org/packages/source/p/django-redis/django-redis-4.7.0.tar.gz', }] } }) elif url == "https://pypi.python.org/packages/source/p/django-redis/django-redis-4.7.0.tar.gz": return _Response(b"Some tarball content\n") elif url == "https://pypi.python.org/pypi/redis/json": return _Response({ 'info': { 'version': '2.10.5', 'name': 'redis', }, 'releases': { '2.10.5': [{ 'url': 'https://pypi.python.org/packages/source/p/redis/redis-2.10.5.tar.gz', }] } }) elif url == "https://pypi.python.org/packages/source/p/redis/redis-2.10.5.tar.gz": return _Response(b"Some other tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run('django-redis==4.7.0', filename, 'sha256', verbose=True) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertTrue('django-redis==4.7.0 \\' in lines) self.assertEqual(len(lines), 2) # Now install the next package whose name is contained # in the first one. my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run('redis==2.10.5', filename, 'sha256', verbose=True) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertTrue('django-redis==4.7.0 \\' in lines) self.assertTrue('redis==2.10.5 \\' in lines) self.assertEqual(len(lines), 4)
def test_run(self, murlopen): def mocked_get(url, **options): if url == "https://pypi.python.org/pypi/hashin/json": return _Response({ 'info': { 'version': '0.10', 'name': 'hashin', }, 'releases': { '0.10': [{ 'url': 'https://pypi.python.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl', }, { 'url': 'https://pypi.python.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl', }, { 'url': 'https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz', }] } }) elif url == "https://pypi.python.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl": return _Response(b"Some py2 wheel content\n") elif url == "https://pypi.python.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl": return _Response(b"Some py3 wheel content\n") elif url == "https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz": return _Response(b"Some tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run('hashin==0.10', filename, 'sha256', verbose=True) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], 'hashin==0.10 \\') self.assertEqual( lines[1], ' --hash=sha256:31104f8c0f9816a6d2135db4232cfa248b2c' '7525596263216577d3cdc93a3c25 \\') self.assertEqual( lines[2], ' --hash=sha256:61fb59231ffe967ce693a2099cff59a2695e' '6d02acbb6b051033e3b1107d8008 \\') self.assertEqual( lines[3], ' --hash=sha256:b2f06d3c4d148b648768abab5086afac0414' 'e49eb4813e1f3c450b975c77cee9') # Now check the verbose output out_lines = my_stdout.getvalue().splitlines() self.assertTrue( 'https://pypi.python.org/pypi/hashin/json' in out_lines[0], out_lines[0]) # url to download self.assertTrue('hashin-0.10-py2-none-any.whl' in out_lines[1], out_lines[1]) # file it got downloaded to self.assertTrue('hashin-0.10-py2-none-any.whl' in out_lines[2], out_lines[2]) # hash it got self.assertTrue( '31104f8c0f9816a6d2135db4232cfa248b2c7525596263216577d3cdc' '93a3c25' in out_lines[3], out_lines[3]) # Change algorithm retcode = hashin.run('hashin==0.10', filename, 'sha512') self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], 'hashin==0.10 \\') self.assertEqual( lines[1], ' --hash=sha512:45d1c5d2237a3b4f78b4198709fb2ecf1f781c823' '4ce3d94356f2100a36739433952c6c13b2843952f608949e6baa9f95055' 'a314487cd8fb3f9d76522d8edb50 \\') self.assertEqual( lines[2], ' --hash=sha512:0d63bf4c115154781846ecf573049324f06b021a1' 'd4b92da4fae2bf491da2b83a13096b14d73e73cefad36855f4fa936bac4' 'b2357dabf05a2b1e7329ff1e5455 \\') self.assertEqual( lines[3], ' --hash=sha512:c32e6d9fb09dc36ab9222c4606a1f43a2dcc183a8' 'c64bdd9199421ef779072c174fa044b155babb12860cf000e36bc4d3586' '94fa22420c997b1dd75b623d4daa')
def test_run(self, murlopen): def mocked_get(url, **options): if url == "https://pypi.org/pypi/hashin/json": return _Response({ 'info': { 'version': '0.10', 'name': 'hashin', }, 'releases': { '0.10': [{ 'url': 'https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl', 'digests': { 'sha256': 'aaaaa', }, }, { 'url': 'https://pypi.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl', 'digests': { 'sha256': 'bbbbb', } }, { 'url': 'https://pypi.org/packages/source/p/hashin/hashin-0.10.tar.gz', 'digests': { 'sha256': 'ccccc', } }] } }) elif url == "https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl": return _Response(b"Some py2 wheel content\n") elif url == "https://pypi.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl": return _Response(b"Some py3 wheel content\n") elif url == "https://pypi.org/packages/source/p/hashin/hashin-0.10.tar.gz": return _Response(b"Some tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run('hashin==0.10', filename, 'sha256', verbose=True) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], 'hashin==0.10 \\') self.assertEqual(lines[1], ' --hash=sha256:aaaaa \\') self.assertEqual(lines[2], ' --hash=sha256:bbbbb \\') self.assertEqual(lines[3], ' --hash=sha256:ccccc') # Now check the verbose output out_lines = my_stdout.getvalue().splitlines() self.assertTrue( 'https://pypi.org/pypi/hashin/json' in out_lines[0], out_lines[0]) # url to download self.assertTrue('hashin-0.10-py2-none-any.whl' in out_lines[1], out_lines[1]) self.assertTrue( 'Found URL https://pypi.org/packages' in out_lines[1], out_lines[1]) # hash it got self.assertTrue('aaaaa' in out_lines[2], out_lines[2]) # Change algorithm retcode = hashin.run('hashin==0.10', filename, 'sha512') self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual(lines[0], 'hashin==0.10 \\') self.assertEqual( lines[1], ' --hash=sha512:0d63bf4c115154781846ecf573049324f06b021a1' 'd4b92da4fae2bf491da2b83a13096b14d73e73cefad36855f4fa936bac4' 'b2357dabf05a2b1e7329ff1e5455 \\') self.assertEqual( lines[2], ' --hash=sha512:45d1c5d2237a3b4f78b4198709fb2ecf1f781c823' '4ce3d94356f2100a36739433952c6c13b2843952f608949e6baa9f95055' 'a314487cd8fb3f9d76522d8edb50 \\') self.assertEqual( lines[3], ' --hash=sha512:c32e6d9fb09dc36ab9222c4606a1f43a2dcc183a8' 'c64bdd9199421ef779072c174fa044b155babb12860cf000e36bc4d3586' '94fa22420c997b1dd75b623d4daa')
def test_run_case_insensitive(self, murlopen): """No matter how you run the cli with a package's case typing, it should find it and correct the cast typing per what it is inside the PyPI data.""" def mocked_get(url, **options): if url == "https://pypi.python.org/pypi/HAShin/json": return _Response({ 'info': { 'version': '0.10', 'name': 'hashin', }, 'releases': { '0.10': [ { 'url': 'https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz', } ] } }) elif url == "https://pypi.python.org/packages/source/p/hashin/hashin-0.10.tar.gz": return _Response(b"Some tarball content\n") elif url == "https://pypi.python.org/pypi/hashIN/json": return _Response({ 'info': { 'version': '0.11', 'name': 'hashin', }, 'releases': { '0.11': [ { 'url': 'https://pypi.python.org/packages/source/p/hashin/hashin-0.11.tar.gz', } ] } }) elif url == "https://pypi.python.org/packages/source/p/hashin/hashin-0.11.tar.gz": return _Response(b"Some different tarball content\n") raise NotImplementedError(url) murlopen.side_effect = mocked_get with tmpfile() as filename: with open(filename, 'w') as f: f.write('') my_stdout = StringIO() with redirect_stdout(my_stdout): retcode = hashin.run( 'HAShin==0.10', filename, 'sha256', verbose=True ) self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual( lines[0], 'hashin==0.10 \\' ) # Change version retcode = hashin.run('hashIN==0.11', filename, 'sha256') self.assertEqual(retcode, 0) with open(filename) as f: output = f.read() assert output.endswith('\n') lines = output.splitlines() self.assertEqual( lines[0], 'hashin==0.11 \\' )