def test_popdist_train(self): gc.collect() executable = get_current_interpreter_executable() out = run_script( "poprun", f"--mpi-global-args='--allow-run-as-root' --num-instances=2 --numa-aware=yes --num-replicas=2 --ipus-per-replica 1 {executable} train/train.py --data cifar10 --model resnet18 --epoch 2 " "--precision 16.16 --optimizer sgd_combined --lr 0.1 --batch-size 2 --gradient-accumulation 16 --enable-stochastic-rounding --validation-mode after --dataloader-worker 4 " "--norm-type group --norm-num-groups 32 --checkpoint-path restore_test_path_test_validation_distributed", python=False) train_acc = get_train_accuracy(out) assert train_acc > 15.0, "training accuracy not improved" test_acc = get_test_accuracy(out) assert test_acc > 15.0, "validation accuracy not improved" # Check the validation accuracy from a single instance out = run_script( "train/validate.py", "--checkpoint-path restore_test_path_test_validation_distributed/resnet18_cifar10_2.pt" ) restored_test_acc = get_test_accuracy(out) assert abs( restored_test_acc - test_acc ) < 0.01, "distributed and single instance validation accuracies doesn't match" # remove folder parent_dir = os.path.dirname(os.path.dirname( os.path.abspath(__file__))) shutil.rmtree( os.path.join(parent_dir, "restore_test_path_test_validation_distributed"))
def test_mixup_cutmix_restore_train(self): # Only make sure that checkpoint loading works with mixup model wrapper. gc.collect() parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) run_script("train/train.py", f"--mixup-alpha 0.1 --cutmix-lambda-low 0.5 --cutmix-lambda-high 0.5 --data generated --checkpoint-path test_mixup_cutmix_restore_train --model resnet18 --epoch 2 --validation-mode none --optimizer sgd_combined --batch-size 4 --dataloader-worker 1 --seed 0") run_script("train/restore.py", "--checkpoint-path test_mixup_cutmix_restore_train/resnet18_generated_1.pt") shutil.rmtree(os.path.join(parent_dir, "test_mixup_cutmix_restore_train"))
def test_multiple_runs_of_setup_function(): '''make sure our fixes support multiple runs ''' from esky.bdist_esky import Executable setup, options, new_script = esky_setup('Simple Working', WORKING_SCRIPT) new_script2 = make_new_script_name('test_multiple_working.py') insert_code(new_script2,'import sys') options2 = copy.deepcopy(options) options2['scripts'] = [new_script2] options2['version'] = '0.2' esky_zip_name = get_zip_name(options2) # Now test that freeze future works as well cleanup_dirs() setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert clean_exit # only works if we cleanup dirs.. same as original esky cleanup_dirs() setup(**options2) if os.name == 'nt': platform = get_platform() esky_zip_name = 'Simple Working-0.2.%s.zip' % platform clean_exit, stderr = run_script(new_script2, freezer='esky', zip_name=esky_zip_name) assert clean_exit
def main(): config = utils.get_configs() if not config['error']: params = config['return'] utils.run_script(params['manga_name'], params['manga_chapters'], params['manga_path']) else: [print(e) for e in config['error']]
def build(self , err=sys.stderr): self.warn_for_dependency() print utils.get_color("blue" , -1 , "b") + "Building Project...\n" + utils.reset_color() try: utils.run_script("scripts/" + self.buildfile , verbose = self.set_verbose , serr=err) except Exception as err: print err print utils.get_color("blue" , -1 , "b") + "Build Complete" + utils.reset_color()
def main(): parser = ArgumentParser(description='Run a migration script.') parser.add_argument('script', help='Script to run') parser.add_argument('config', help='Service config file') parser.add_argument('secrets', help='Service database admin secrets') args = parser.parse_args() run_script(args.script, args.config, args.secrets)
def run(self , iname=0 , oname=0 , err=sys.stderr): sin = self.get_file(iname , sys.stdin) sout= self.get_file(oname , sys.stdout , "w") print utils.get_color("blue" , -1 , "b") + "Running Project...\n" + utils.reset_color() try: utils.run_script("scripts/" + self.runfile , True , sin , sout , verbose = self.set_verbose , serr = err) except Exception as err: print err.args print utils.get_color("blue" , -1 , "b") + "Run Complete" + utils.reset_color()
def debug(self , iname=0 , oname=0): sin = self.get_file(iname , sys.stdin) sout= self.get_file(oname , sys.stdout , "w") print utils.get_color("blue" , -1 , "b") + "Debugging Project...\n" + utils.reset_color() try: utils.run_script("scripts/" + self.debugfile , True , sin , sout , verbose = self.set_verbose) except Exception as err: print err.args print utils.get_color("blue" , -1 , "b") + "Debug Complete\n" + utils.reset_color()
def _resize_window_mac(self, pid, pos_x, pos_y, w, h): ''' Issues command ''' print("Inner command: ", pid) inner_cmd = f"""tell application "System Events" tell processes whose unix id is {pid} set size of front window to {{{w}, {h}}} set position of front window to {{{pos_x}, {pos_y}}} end tell end tell""" run_script('osascript', inner_cmd.encode('utf-8'))
def test_restore_train(self): gc.collect() # create a model out = run_script("train/train.py", "--data cifar10 --epoch 2 --model resnet18 --precision 16.16 --optimizer sgd_combined --lr 0.1 --batch-size 2 --gradient-accumulation 32 --seed 0 " "--validation-mode none --norm-type group --norm-num-groups 32 --checkpoint-path restore_test_path_test_restore_train --dataloader-worker 4") saved_train_acc = get_train_accuracy(out) # reload the model out = run_script("train/restore.py", "--checkpoint-path restore_test_path_test_restore_train/resnet18_cifar10_1.pt") acc = get_train_accuracy(out) assert acc > saved_train_acc - 5.0 # remove folder parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) shutil.rmtree(os.path.join(parent_dir, "restore_test_path_test_restore_train"))
def test_webdataset_creation(self): raw_path = Path(__file__).parent.parent.absolute().joinpath("data").joinpath("cifar10_raw") converted_path = Path(__file__).parent.parent.absolute().joinpath("data").joinpath("test_cifar10_webdata_creation") # create train folder from validation if not os.path.exists(os.path.join(raw_path, "train")): shutil.copytree(os.path.join(raw_path, "validation"), os.path.join(raw_path, "train")) run_script("datasets/create_webdataset.py", f"--source {raw_path} --target {converted_path} --shuffle --seed 0 --format tensor --samples-per-shard 200") out = run_script("datasets/validate_dataset.py", f"--imagenet-data-path {converted_path}") num_files = len(os.listdir(converted_path)) shutil.rmtree(converted_path) shutil.rmtree(os.path.join(raw_path, "train")) assert "Dataset OK." in out assert num_files == 2 * 50 + 1
def test_webdataset_distribution(self): """Smoke test for distributed webdataset generation. """ webdata_path = Path(__file__).parent.parent.absolute().joinpath("data").joinpath("cifar10_webdata") distributed_folder = os.path.join(webdata_path, "distributed", "8-instances") if os.path.exists(distributed_folder): shutil.rmtree(distributed_folder) run_script("datasets/distributed_webdataset.py", f"--target {webdata_path} --num-instances 8") assert os.path.exists(distributed_folder) num_files = len(os.listdir(distributed_folder)) shutil.rmtree(distributed_folder) assert num_files == 2 * 8
def test_weight_avg(self): gc.collect() parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) out1 = run_script("train/train.py", "--data cifar10 --epoch 3 --model resnet18 --precision 16.16 --weight-avg-strategy mean --norm-type group " "--norm-num-groups 32 --optimizer sgd_combined --lr 0.1 --batch-size 2 --gradient-accumulation 32 --checkpoint-path restore_test_path_weight_avg " "--weight-avg-N 2 --dataloader-worker 4 --seed 0") os.remove(os.path.join(parent_dir, "restore_test_path_weight_avg", "resnet18_cifar10_3_averaged.pt")) _ = run_script("train/weight_avg.py", "--checkpoint-path restore_test_path_weight_avg --weight-avg-strategy mean --weight-avg-N 2") out2 = run_script("train/validate.py", "--checkpoint-path restore_test_path_weight_avg/resnet18_cifar10_3_averaged.pt") acc1 = get_test_accuracy(out1) acc2 = get_test_accuracy(out1) assert acc1 > 15 assert acc1 == acc2 shutil.rmtree(os.path.join(parent_dir, "restore_test_path_weight_avg"))
def test_py2app_work_with_no_standard_library(): '''does our code with without the standard librar function call''' setup, options, new_script = py2app_setup('py2app works_nostandardlin', 'py2app_works_no_stdlib.py') insert_code(new_script, "from __future__ import absolute_import, division, print_function", "from builtins import (bytes, str, open, super, range,", " zip, round, input, int, pow, object)") freeze_future.setup(**options) if PY3: clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit else: #with pytest.raises(Exception):# I think my exit code is shadowing the exception or sth?? or my sys.exit call clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit
def test_p2exe_working(): '''Test a small script to make sure it builds properly We have to insert import py2exe into our setup script''' setup, options, name = py2exe_setup('Simple Working', WORKING_SCRIPT) setup(**options) clean_exit, stderr = run_script(WORKING_SCRIPT, freezer='py2exe') assert clean_exit
def test_py2app_builds_and_runs(): '''Test a small script to make sure it builds properly''' setup, options, new_script = py2app_setup('Simple Working', WORKING_SCRIPT) setup(**options) #TODO MAKE SURE run_script runs as it should... clean_exit, stderr = run_script(WORKING_SCRIPT, freezer='py2app') assert clean_exit
def start(): data = json.loads(request.get_data()) code, out, err = run_script(current_app, data.get('script_name'), data.get('options')) if code == 0: if err: logger.info( "The run was successful but with warnings: {}".format(err)) to_return = { "status": "Success with warnings", "output": out, "error": err } else: logger.info("The run was successful: {}".format(out)) to_return = {"status": "Success", "output": out} return json.dumps(to_return), 200 else: logger.warning("The run had an error. Output: {}, Error: {}".format( out, err)) return json.dumps({ "status": "Error", "output": out, "error": err }), 500
def test_train_config_compile(config): gc.collect() out = run_script( "train/train.py", f"--data generated --config {config} --compile-only --checkpoint-path temp_folder" ) assert not ("ERROR" in out)
def expand_location(path): # if isinstance(path, file): if is_file(path): path = path.name if path.startswith('https://s3-external-1.amazonaws.com/') or path.startswith('https://s3.amazonaws.com/'): # it's being downloaded from a bucket, no worries return path # resolve any symlinks # the backfill uses symlinks to the article-xml dir path = os.path.abspath(os.path.realpath(path)) if re.match(r".*article-xml/articles/.+\.xml$", path): # this article is coming from the local ./article-xml/ directory, which # is almost certainly a git checkout. we want a location that looks like: # https://raw.githubusercontent.com/elifesciences/elife-article-xml/5f1179c24c9b8a8b700c5f5bf3543d16a32fbe2f/articles/elife-00003-v1.xml rc, rawsha = utils.run_script(["cat", "elife-article-xml.sha1"]) ensure(rc == 0, "failed to read the contents of './elife-article-xml.sha1'") sha = rawsha.strip() fname = os.path.basename(path) return "https://raw.githubusercontent.com/elifesciences/elife-article-xml/%s/articles/%s" % (sha, fname) # who knows what this path is ... LOG.warn("scraping article content in a non-repeatable way. path %r not found in article-xml dir. please don't send the results to lax", path) return path
def test_esky_bundle_mscrvt(): setup, options, new_script = esky_setup('Simple Working', WORKING_SCRIPT) # setup(**options) new_script2 = make_new_script_name('testing_patching.py') insert_code(new_script2, 'import sys', 'import os', 'versiondir = os.path.dirname(sys.executable)', 'for nm in os.listdir(versiondir):', ' if nm.startswith("Microsoft.") and nm.endswith(".CRT"):', ' msvcrt_dir = os.path.join(versiondir,nm)', ' assert os.path.isdir(msvcrt_dir)', ' assert len(os.listdir(msvcrt_dir)) >= 2', ' break', 'else:', ' assert False, "MSVCRT not bundled in version dir "+versiondir') options2 = copy.deepcopy(options) options2['options']['bdist_esky']['bundle_msvcrt'] = True options2['scripts'] = [new_script2] # options2['script_args'] = ['bdist_esky_patch'] options2['version'] = '2.0' setup(**options2) # esky_zip_name = 'Simple Working-0.2.win32.zip' esky_zip_name = get_zip_name(options2) clean_exit, stderr = run_script(new_script2, freezer='esky', zip_name=esky_zip_name) assert clean_exit
def test_cxfreeze_failure_condition(): '''Our script fails to build under certain platforms and python versions due to dependancies not being found by our freezer, we need to manually include/exclude them''' setup, options, new_script = cxfreeze_setup('test_condition', 'test_condition.py') insert_code( new_script, "from future import standard_library", "standard_library.install_aliases()", ) if 'linux' in sys.path or 'darwin' in sys.platform: #TODO confirm that mac handles the same as linux.. if not PY3: with pytest.raises(Exception): setup(**options) else: setup(**options) elif sys.platform == 'win32': setup(**options) clean_exit, stderr = run_script(new_script, freezer='cxfreeze') if PY3: assert clean_exit else: #this failure condition is from cxfreeze and py2exe.. missing modules .. assert not clean_exit
def test_cxfreeze_builds_and_runs(): '''Test a small script to make sure it builds properly''' setup, options, new_script = cxfreeze_setup('Simple Working', WORKING_SCRIPT) setup(**options) clean_exit, stderr = run_script(WORKING_SCRIPT, freezer='cxfreeze') assert clean_exit
def expand_location(path): # if isinstance(path, file): if is_file(path): path = path.name if path.startswith('https://s3-external-1.amazonaws.com/' ) or path.startswith('https://s3.amazonaws.com/'): # it's being downloaded from a bucket, no worries return path # resolve any symlinks # the backfill uses symlinks to the article-xml dir path = os.path.abspath(os.path.realpath(path)) if re.match(r".*article-xml/articles/.+\.xml$", path): # this article is coming from the local ./article-xml/ directory, which # is almost certainly a git checkout. we want a location that looks like: # https://raw.githubusercontent.com/elifesciences/elife-article-xml/5f1179c24c9b8a8b700c5f5bf3543d16a32fbe2f/articles/elife-00003-v1.xml rc, rawsha = utils.run_script(["cat", "elife-article-xml.sha1"]) ensure(rc == 0, "failed to read the contents of './elife-article-xml.sha1'") sha = rawsha.strip() fname = os.path.basename(path) return "https://raw.githubusercontent.com/elifesciences/elife-article-xml/%s/articles/%s" % ( sha, fname) # who knows what this path is ... LOG.warn( "scraping article content in a non-repeatable way. path %r not found in article-xml dir. please don't send the results to lax", path) return path
def test_inference_config(config): gc.collect() out = run_script( "inference/run_benchmark.py", f"--data generated --config {config} --dataloader-worker 2 --iterations 5 --device-iteration 1" ) assert not ("ERROR" in out)
def test_py2app_future_condition_3_fix(): '''tests our fix when importing everything under the sun!''' setup, options, new_script = py2app_setup('py2app fixed', 'py2app_fixed.py') insert_code(new_script, 'import past') freeze_future.setup(**options) clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit
def test_py2app_failure_condition2(): '''this module was playing up so testing it ..''' setup, options, new_script = py2app_setup('test_condition2', 'test_condition2.py') insert_code(new_script, "from __future__ import print_function",) setup(**options) clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit
def test_esky_freeze_future_condition_two_fix(): ''' Testing adding the future imports doesn't f**k up the building on python3 F***s up python2 though Esky allows setup to compile, but the script will not run ''' setup, options, new_script = esky_setup('Working with Future Import', 'esky_future_working.py') insert_code(new_script, "from __future__ import print_function",) if PY3: freeze_future.setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert clean_exit else: freeze_future.setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert not clean_exit
def test_esky_freeze_future_condition_three_fix(): '''explictly telling freeze future we are using esky and cxfreeze''' setup, options, new_script = esky_setup('cxfreeze_esky_fixed', 'esky_cxfreeze_fixed.py') insert_code(new_script, "import past",) setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert clean_exit
def test_esky_builds_and_runs(): '''Test a small script to make sure it builds properly If this fails it means you have a problem with ESKY so go fix it!!! ''' setup, options, new_script = esky_setup('Simple Working', WORKING_SCRIPT) setup(**options) clean_exit, stderr = run_script(WORKING_SCRIPT, freezer='esky') print(stderr) assert clean_exit
def test_py2exe_failure_condition2(): '''this module was playing up so testing it ..''' setup, options, new_script = py2exe_setup('test_condition2', 'test_condition2.py') insert_code(new_script, "from __future__ import print_function",) setup(**options) clean_exit, stderr = run_script(new_script, freezer='py2exe') assert clean_exit
def test_py2app_work_with_no_standard_library(): '''does our code with without the standard librar function call''' setup, options, new_script = py2app_setup('py2app works_nostandardlin', 'py2app_works_no_stdlib.py') insert_code( new_script, "from __future__ import absolute_import, division, print_function", "from builtins import (bytes, str, open, super, range,", " zip, round, input, int, pow, object)") freeze_future.setup(**options) if PY3: clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit else: #with pytest.raises(Exception):# I think my exit code is shadowing the exception or sth?? or my sys.exit call clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit
def test_popdist_inference(self): executable = get_current_interpreter_executable() out = run_script( "poprun", f"--mpi-global-args='--allow-run-as-root' --num-instances=2 --numa-aware=yes --num-replicas=2 {executable} inference/run_benchmark.py --data generated --model resnet18 --batch-size 4 --precision 16.16 --iterations 10 --dataloader-worker 4", python=False) max_thoughput = get_max_thoughput(out) assert max_thoughput > 0
def test_cxfreeze_future_condition_3_fix(): '''tests our fix when importing everything under the sun! also import builtins TBD this test is a bit flakey when running the entire suite and doing tests on py 2 and py3''' setup, options, new_script = cxfreeze_setup('cxfreeze fixed', 'cxfreeze_fixed.py') insert_code(new_script, 'import past') freeze_future.setup(**options) clean_exit, stderr = run_script(new_script, freezer='cxfreeze') assert clean_exit
def call_lax(action, msid, version, token, article_json=None, force=False, dry_run=False): #raise EnvironmentError("whoooooa. no.") cmd = [ find_lax(), # /srv/lax/manage.sh "--skip-install", "ingest", "--" + action, # ll: --ingest+publish "--serial", "--id", str(msid), "--version", str(version), ] if dry_run: cmd += ["--dry-run"] if force: cmd += ["--force"] lax_stdout = None try: rc, lax_stdout = utils.run_script(cmd, article_json) lax_resp = json.loads(lax_stdout) bot_lax_resp = { "id": msid, "status": None, # not present in success responses # added in error responses # "message": # "code": # "comment": "datetime": datetime.now(), # additional attributes we'll be returning "action": action, "force": force, "dry-run": dry_run, "token": token, } # ensure everything that lax returns is preserved # valid adaptor responses are handled in `mkresponse` # valid api responses are handled in api.post_xml bot_lax_resp.update(lax_resp) bot_lax_resp['id'] = str(bot_lax_resp['id']) return bot_lax_resp except ValueError as err: # could not parse lax response. this is a lax error raise RuntimeError( "failed to parse response from lax, expecting json, got error %r from stdout %r" % (str(err), lax_stdout))
def send_api_query(endpoint, params, fmt, context): if fmt is not None: params['format'] = fmt.strip() if context.table: if context.table.headings[0] == 'param': for line in context.table: params[line['param']] = line['value'] else: for h in context.table.headings: params[h] = context.table[0][h] env = dict(BASE_SERVER_ENV) env['QUERY_STRING'] = urlencode(params) env['SCRIPT_NAME'] = '/%s.php' % endpoint env['REQUEST_URI'] = '%s?%s' % (env['SCRIPT_NAME'], env['QUERY_STRING']) env['CONTEXT_DOCUMENT_ROOT'] = os.path.join( context.nominatim.website_dir.name, 'website') env['SCRIPT_FILENAME'] = os.path.join(env['CONTEXT_DOCUMENT_ROOT'], '%s.php' % endpoint) LOG.debug("Environment:" + json.dumps(env, sort_keys=True, indent=2)) if hasattr(context, 'http_headers'): env.update(context.http_headers) cmd = ['/usr/bin/env', 'php-cgi', '-f'] if context.nominatim.code_coverage_path: env['COV_SCRIPT_FILENAME'] = env['SCRIPT_FILENAME'] env['COV_PHP_DIR'] = os.path.join(context.nominatim.src_dir, "lib") env['COV_TEST_NAME'] = '%s:%s' % (context.scenario.filename, context.scenario.line) env['SCRIPT_FILENAME'] = \ os.path.join(os.path.split(__file__)[0], 'cgi-with-coverage.php') cmd.append(env['SCRIPT_FILENAME']) env['PHP_CODE_COVERAGE_FILE'] = context.nominatim.next_code_coverage_file( ) else: cmd.append(env['SCRIPT_FILENAME']) for k, v in params.items(): cmd.append("%s=%s" % (k, v)) outp, err = run_script(cmd, cwd=context.nominatim.website_dir.name, env=env) assert len(err) == 0, "Unexpected PHP error: %s" % (err) if outp.startswith('Status: '): status = int(outp[8:11]) else: status = 200 content_start = outp.find('\r\n\r\n') return outp[content_start + 4:], status
def test_esky_failure_condition_fixed(): setup, options, new_script = esky_setup('test_condition', 'test_condition.py') insert_code(new_script, "from future import standard_library", "standard_library.install_aliases()",) setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert clean_exit
def test_esky_failure_condition2_fixed(): '''this error isn't mine to fix here, it is not present in the freezers o.0''' setup, options, new_script = esky_setup('test_condition2', 'test_condition2.py') insert_code(new_script, "from __future__ import print_function",) fail_cond = 'The process cannot access the file because it is being used by another process' setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert clean_exit
def test_half_resolution_training(self): gc.collect() out = run_script("train/train.py", "--data cifar10 --model resnet18 --epoch 1 --precision 16.32 --optimizer sgd_combined --lr 0.1 --batch-size 2 --gradient-accumulation 32 " "--norm-type batch --dataloader-worker 4 --half-res-training --fine-tune-epoch 1 --fine-tune-first-trainable-layer layer3 --weight-avg-strategy exponential " "--weight-avg-exp-decay 0.97 --checkpoint-path test_half_resolution_training --seed 0") acc = get_test_accuracy(out) assert acc > 15.0 # remove folder parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) shutil.rmtree(os.path.join(parent_dir, "test_half_resolution_training"))
def test_setuptools_condition2(): '''Testing adding the future imports doesn't f**k up the building''' setup, options, new_script = setuptools_setup('Working with Future Import', 'future_working.py') insert_code(new_script, "from __future__ import print_function") setup(**options) clean_exit, stderr = run_script(new_script, freezer='setuptools') assert clean_exit
def test_py2app_failure_condition3_fixed(): ''' basically using open function on a datafile will fail if the modulea and datafiles are inside a zip as open doesn't know how to look in a zip. Error -> No such file or directory grammer.txt https://bitbucket.org/anthony_tuininga/cx_freeze/issues/151/using-modules-that-use-open-on-data-files''' setup, options, new_script = py2app_setup('test_condition3', 'test_condition3.py') insert_code(new_script, "import past") # 'from past.builtins import basestring') setup(**options) clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit
def test_py2app_freeze_future_condition_one_fix(): '''tests our fix when importing everything under the sun!, just another sanity check''' setup, options, new_script = py2app_setup('py2app fixed', 'py2app_fixed.py') insert_code(new_script, "from future import standard_library", "standard_library.install_aliases()", "import urllib.request, urllib.error, urllib.parse", "import collections", "from itertools import filterfalse", "from subprocess import getoutput", "from builtins import str", "from builtins import range",) freeze_future.setup(**options) clean_exit, stderr = run_script(new_script, freezer='py2app') assert clean_exit
def call_lax(action, msid, version, token, article_json=None, force=False, dry_run=False): #raise EnvironmentError("whoooooa. no.") cmd = [ find_lax(), # /srv/lax/manage.sh "--skip-install", "ingest", "--" + action, # ll: --ingest+publish "--serial", "--id", str(msid), "--version", str(version), ] if dry_run: cmd += ["--dry-run"] if force: cmd += ["--force"] lax_stdout = None try: rc, lax_stdout = utils.run_script(cmd, article_json) lax_resp = json.loads(lax_stdout) bot_lax_resp = { "id": msid, "status": None, # not present in success responses # added in error responses # "message": # "code": # "comment": "datetime": datetime.now(), # additional attributes we'll be returning "action": action, "force": force, "dry-run": dry_run, "token": token, } # ensure everything that lax returns is preserved # valid adaptor responses are handled in `mkresponse` # valid api responses are handled in api.post_xml bot_lax_resp.update(lax_resp) bot_lax_resp['id'] = str(bot_lax_resp['id']) return bot_lax_resp except ValueError as err: # could not parse lax response. this is a lax error raise RuntimeError("failed to parse response from lax, expecting json, got error %r from stdout %r" % (str(err), lax_stdout))
def test_esky_bdist_esky_patch_command(): '''this test is overkill just need to make sure patch command returns esky''' # TODO this made it clear i need to force the selection of freezer rather trying than smart detect it setup, options, new_script = esky_setup('Simple Working', WORKING_SCRIPT) setup(**options) new_script2 = make_new_script_name('testing_patching.py') insert_code(new_script2,'import sys') options2 = copy.deepcopy(options) options2['scripts'] = [new_script2] options2['script_args'] = ['bdist_esky_patch'] options2['version'] = '0.2' setup(**options2) esky_zip_name = get_zip_name(options2) clean_exit, stderr = run_script(new_script2, freezer='esky', zip_name=esky_zip_name) assert clean_exit
def test_esky_freeze_future_condition_one_fix(): '''tests our fix when importing everything under the sun! also import builtins''' setup, options, new_script = esky_setup('esky fixed2', 'esky_fixed2.py') insert_code(new_script, "from future import standard_library", "standard_library.install_aliases()", "import urllib.request, urllib.error, urllib.parse", "import collections", "from itertools import filterfalse", "from subprocess import getoutput", "from builtins import str", "from builtins import range", "from queue import Queue") setup(**options) clean_exit, stderr = run_script(new_script, freezer='esky') assert clean_exit
def test_setuptools_condition(): '''Testing adding the future imports doesn't f**k up the building''' setup, options, new_script = setuptools_setup('cxfreeze fixed', 'cxfreeze_fixed.py') insert_code(new_script, "from future import standard_library", "standard_library.install_aliases()", "import urllib.request, urllib.error, urllib.parse", "import collections", "from itertools import filterfalse", "from subprocess import getoutput", "from builtins import str", "from builtins import range",) setup(**options) clean_exit, stderr = run_script(new_script, freezer='setuptools') assert clean_exit
def test_cxfreeze_failure_condition(): '''Our script fails to build under certain platforms and python versions due to dependancies not being found by our freezer, we need to manually include/exclude them''' setup, options, new_script = cxfreeze_setup('test_condition', 'test_condition.py') insert_code(new_script, "from future import standard_library", "standard_library.install_aliases()",) if 'linux' in sys.path or 'darwin' in sys.platform: #TODO confirm that mac handles the same as linux.. if not PY3: with pytest.raises(Exception): setup(**options) else: setup(**options) elif sys.platform == 'win32': setup(**options) clean_exit, stderr = run_script(new_script, freezer='cxfreeze') if PY3: assert clean_exit else: #this failure condition is from cxfreeze and py2exe.. missing modules .. assert not clean_exit
def test_setuptools_working(): '''Test a small script to make sure it builds properly''' setup, options, name = setuptools_setup('Simple Working', WORKING_SCRIPT) setup(**options) assert run_script(WORKING_SCRIPT, freezer='setuptools')