Add test and remove unused args (#951)
Followup to #930: Add a tests, and remove newly-unused arguments to unzip and untargz.
This commit is contained in:
16
emsdk.py
16
emsdk.py
@@ -535,11 +535,7 @@ def run(cmd, cwd=None, quiet=False):
|
||||
|
||||
|
||||
# http://pythonicprose.blogspot.fi/2009/10/python-extract-targz-archive.html
|
||||
def untargz(source_filename, dest_dir, unpack_even_if_exists=False):
|
||||
debug_print('untargz(source_filename=' + source_filename + ', dest_dir=' + dest_dir + ')')
|
||||
if not unpack_even_if_exists and num_files_in_directory(dest_dir) > 0:
|
||||
print("File '" + source_filename + "' has already been unpacked, skipping.")
|
||||
return True
|
||||
def untargz(source_filename, dest_dir):
|
||||
print("Unpacking '" + source_filename + "' to '" + dest_dir + "'")
|
||||
mkdir_p(dest_dir)
|
||||
returncode = run(['tar', '-xvf' if VERBOSE else '-xf', sdk_path(source_filename), '--strip', '1'], cwd=dest_dir)
|
||||
@@ -579,11 +575,7 @@ def move_with_overwrite(src, dest):
|
||||
|
||||
|
||||
# http://stackoverflow.com/questions/12886768/simple-way-to-unzip-file-in-python-on-all-oses
|
||||
def unzip(source_filename, dest_dir, unpack_even_if_exists=False):
|
||||
debug_print('unzip(source_filename=' + source_filename + ', dest_dir=' + dest_dir + ')')
|
||||
if not unpack_even_if_exists and num_files_in_directory(dest_dir) > 0:
|
||||
print("File '" + source_filename + "' has already been unpacked, skipping.")
|
||||
return True
|
||||
def unzip(source_filename, dest_dir):
|
||||
print("Unpacking '" + source_filename + "' to '" + dest_dir + "'")
|
||||
mkdir_p(dest_dir)
|
||||
common_subdir = None
|
||||
@@ -1552,9 +1544,9 @@ def download_and_unzip(zipfile, dest_dir, download_even_if_exists=False,
|
||||
if clobber:
|
||||
remove_tree(dest_dir)
|
||||
if zipfile.endswith('.zip'):
|
||||
return unzip(download_target, dest_dir, unpack_even_if_exists=True)
|
||||
return unzip(download_target, dest_dir)
|
||||
else:
|
||||
return untargz(download_target, dest_dir, unpack_even_if_exists=True)
|
||||
return untargz(download_target, dest_dir)
|
||||
|
||||
|
||||
def to_native_path(p):
|
||||
|
||||
14
test/test.py
14
test/test.py
@@ -40,11 +40,11 @@ def check_call(cmd, **args):
|
||||
subprocess.check_call(cmd, **args)
|
||||
|
||||
|
||||
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None):
|
||||
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None, env=None):
|
||||
cmd = cmd.split(' ')
|
||||
print('running: %s' % cmd)
|
||||
try:
|
||||
stdout = subprocess.check_output(cmd, stderr=stderr, universal_newlines=True)
|
||||
stdout = subprocess.check_output(cmd, stderr=stderr, universal_newlines=True, env=env)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.stderr)
|
||||
print(e.stdout)
|
||||
@@ -272,6 +272,16 @@ int main() {
|
||||
run_emsdk('install latest')
|
||||
failing_call_with_output(emsdk + ' activate 2.0.1', expected="error: tool is not installed and therefore cannot be activated: 'releases-upstream-13e29bd55185e3c12802bc090b4507901856b2ba-64bit'")
|
||||
|
||||
def test_keep_downloads(self):
|
||||
env = os.environ.copy()
|
||||
env['EMSDK_KEEP_DOWNLOADS'] = '1'
|
||||
# With EMSDK_KEEP_DOWNLOADS the downloading should happen on the first
|
||||
# install of 2.0.28, and again when we install 2.0.29, but not on the
|
||||
# second install of 2.0.28 because the zip should already be local.
|
||||
checked_call_with_output(emsdk + ' install 2.0.28', expected='Downloading:', env=env)
|
||||
checked_call_with_output(emsdk + ' install 2.0.29', expected='Downloading:', env=env)
|
||||
checked_call_with_output(emsdk + ' install 2.0.28', expected='already downloaded, skipping', unexpected='Downloading:', env=env)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user