def test_multiple(self): self.assertEqual(binary_replace(b'aaaacaaaa\x00', b'aaaa', b'bbbb'), b'bbbbcbbbb\x00') self.assertEqual(binary_replace(b'aaaacaaaa\x00', b'aaaa', b'bbb'), b'bbbcbbb\x00\x00\x00') self.assertRaises(_PaddingError, binary_replace, b'aaaacaaaa\x00', b'aaaa', b'bbbbb')
def test_windows_entry_point(self): """ This emulates pip-created entry point executables on windows. For more info, refer to conda/install.py::replace_entry_point_shebang """ tmp_dir = tempfile.mkdtemp() cwd = getcwd() chdir(tmp_dir) original_prefix = "C:\\BogusPrefix\\python.exe" try: url = 'https://bitbucket.org/vinay.sajip/pyzzer/downloads/pyzzerw.pyz' download(url, 'pyzzerw.pyz') url = 'https://files.pythonhosted.org/packages/source/c/conda/conda-4.1.6.tar.gz' download(url, 'conda-4.1.6.tar.gz') subprocess.check_call( [ sys.executable, 'pyzzerw.pyz', # output file '-o', 'conda.exe', # entry point '-m', 'conda.cli.main:main', # initial shebang '-s', '#! ' + original_prefix, # launcher executable to use (32-bit text should be compatible) '-l', 't32', # source archive to turn into executable 'conda-4.1.6.tar.gz', ], cwd=tmp_dir) # this is the actual test: change the embedded prefix and make sure that the exe runs. data = open('conda.exe', 'rb').read() fixed_data = binary_replace(data, original_prefix, sys.executable) with open("conda.fixed.exe", 'wb') as f: f.write(fixed_data) # without a valid shebang in the exe, this should fail with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(['conda.exe', '-h']) process = subprocess.Popen(['conda.fixed.exe', '-h'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() output = output.decode('utf-8') error = error.decode('utf-8') assert ("conda is a tool for managing and deploying applications, " "environments and packages.") in output except: raise finally: chdir(cwd)
def test_windows_entry_point(self): """ This emulates pip-created entry point executables on windows. For more info, refer to conda/install.py::replace_entry_point_shebang """ tmp_dir = tempfile.mkdtemp() cwd = getcwd() chdir(tmp_dir) original_prefix = "C:\\BogusPrefix\\python.exe" try: url = "https://bitbucket.org/vinay.sajip/pyzzer/downloads/pyzzerw.pyz" download(url, "pyzzerw.pyz") url = "https://files.pythonhosted.org/packages/source/c/conda/conda-4.1.6.tar.gz" download(url, "conda-4.1.6.tar.gz") subprocess.check_call( [ sys.executable, "pyzzerw.pyz", # output file "-o", "conda.exe", # entry point "-m", "conda.cli.main:main", # initial shebang "-s", "#! " + original_prefix, # launcher executable to use (32-bit text should be compatible) "-l", "t32", # source archive to turn into executable "conda-4.1.6.tar.gz", ], cwd=tmp_dir, ) # this is the actual test: change the embedded prefix and make sure that the exe runs. data = open("conda.exe", "rb").read() fixed_data = binary_replace(data, original_prefix, sys.executable) with open("conda.fixed.exe", "wb") as f: f.write(fixed_data) # without a valid shebang in the exe, this should fail with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(["conda.exe", "-h"]) process = subprocess.Popen(["conda.fixed.exe", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() output = output.decode("utf-8") error = error.decode("utf-8") assert ("conda is a tool for managing and deploying applications, " "environments and packages.") in output except: raise finally: chdir(cwd)
def test_spaces(self): self.assertEqual(binary_replace(b' aaaa \x00', b'aaaa', b'bbbb'), b' bbbb \x00')
def test_two(self): self.assertEqual( binary_replace(b'aaaaa\x001234aaaaacc\x00\x00', b'aaaaa', b'bbbbb'), b'bbbbb\x001234bbbbbcc\x00\x00')
def test_no_extra(self): self.assertEqual(binary_replace(b'aaaaa\x00', b'aaaaa', b'bbbbb'), b'bbbbb\x00')
def test_shorter(self): self.assertEqual( binary_replace(b'xxxaaaaaxyz\x00zz', b'aaaaa', b'bbbb'), b'xxxbbbbxyz\x00\x00zz')
def test_multiple(self): self.assertEqual(binary_replace(b"aaaacaaaa\x00", b"aaaa", b"bbbb"), b"bbbbcbbbb\x00") self.assertEqual(binary_replace(b"aaaacaaaa\x00", b"aaaa", b"bbb"), b"bbbcbbb\x00\x00\x00") self.assertRaises(_PaddingError, binary_replace, b"aaaacaaaa\x00", b"aaaa", b"bbbbb")
def test_spaces(self): self.assertEqual(binary_replace(b" aaaa \x00", b"aaaa", b"bbbb"), b" bbbb \x00")
def test_two(self): self.assertEqual( binary_replace(b"aaaaa\x001234aaaaacc\x00\x00", b"aaaaa", b"bbbbb"), b"bbbbb\x001234bbbbbcc\x00\x00" )
def test_no_extra(self): self.assertEqual(binary_replace(b"aaaaa\x00", b"aaaaa", b"bbbbb"), b"bbbbb\x00")
def test_shorter(self): self.assertEqual(binary_replace(b"xxxaaaaaxyz\x00zz", b"aaaaa", b"bbbb"), b"xxxbbbbxyz\x00\x00zz")