Skip to content

Commit

Permalink
Add test and remove unused args (emscripten-core#951)
Browse files Browse the repository at this point in the history
Followup to emscripten-core#930: Add a tests, and remove newly-unused arguments
to unzip and untargz.
  • Loading branch information
sbc100 authored Dec 23, 2021
1 parent 8e7b714 commit 4764bfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 4 additions & 12 deletions emsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 12 additions & 2 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -272,6 +272,16 @@ def test_activate_missing(self):
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)

0 comments on commit 4764bfa

Please sign in to comment.