def test_print_3(self): """ It can escape some characters: \" or \' and \\ """ self.assertEqual(run(r'print, "\"\""'), '""') self.assertEqual(run(r"print, '\'\''"), "''") self.assertEqual(run(r"print, '\\'"), "\\")
def test_print_2(self): """ There is two way to show the string: "xxx" and 'xxx', like python. """ self.assertEqual(run('''print, "this is the 'string'!" '''), "this is the 'string'!") self.assertEqual(run('''print, 'this is the "string"!' '''), 'this is the "string"!')
def test_nosizetool_should_throw(): check_env('PATH_TO_EZSTACK') PATH_TO_EZSTACK = os.environ['PATH_TO_EZSTACK'] arg = Arguments(size='', elf=AVR_ELF_FILE_PATH, ezstack=PATH_TO_EZSTACK, mcu=AVR_MCU, maxflash=0, maxram=0) with pytest.raises(FileNotFoundError): run(arg)
def test_wrong_mcu_should_throw(): check_env('PATH_TO_AVR_SIZE_TOOL') check_env('PATH_TO_EZSTACK') PATH_TO_AVR_SIZE_TOOL = os.environ['PATH_TO_AVR_SIZE_TOOL'] PATH_TO_EZSTACK = os.environ['PATH_TO_EZSTACK'] arg = Arguments(size=PATH_TO_AVR_SIZE_TOOL, elf=AVR_ELF_FILE_PATH, ezstack=PATH_TO_EZSTACK, mcu='123', maxflash=0, maxram=0) with pytest.raises(Exception): run(arg)
def test_noelffile_should_throw(): check_env('PATH_TO_AVR_SIZE_TOOL') check_env('PATH_TO_EZSTACK') PATH_TO_AVR_SIZE_TOOL = os.environ['PATH_TO_AVR_SIZE_TOOL'] PATH_TO_EZSTACK = os.environ['PATH_TO_EZSTACK'] arg = Arguments(size=PATH_TO_AVR_SIZE_TOOL, elf='', ezstack=PATH_TO_EZSTACK, mcu=AVR_MCU, maxflash=0, maxram=0) with pytest.raises(FileNotFoundError) as e: run(arg)
def test_print_1(self): """ I hope it can work like this: >>> print, "this is the string..." ... this is the string... """ self.assertEqual(run('print, "this is the string..."'), "this is the string...") # the white space do not make the result different self.assertEqual( run(' print , "this is the string..." '), "this is the string...") # but endiff result if in string: self.assertEqual(run('print, "this is the string..."'), "this is the string...")
def test_experiment_run_and_compare(): for data_path in datasets: accuracies = {} learner_types = ['prior_probability', 'decision_tree'] for learner_type in learner_types: accuracies[learner_type] = run(data_path, learner_type, 1.0)[1] if 'candy' in data_path or 'ivy' in data_path: assert (accuracies['decision_tree'] > accuracies['prior_probability'])
def test_experiment_run_prior_probability(): accuracies = {} for data_path in datasets: learner_type = 'prior_probability' confusion_matrix, accuracy, precision, recall, f1_measure = (run( data_path, learner_type, 1.0)) accuracies[data_path] = accuracy dataset = xp_dataset_name('ivy-league.csv') assert (accuracies[dataset] > .2)
def test_experiment_run_decision_tree(): accuracies = {} for data_path in datasets: learner_type = 'decision_tree' confusion_matrix, accuracy, precision, recall, f1_measure = (run( data_path, learner_type, 1.0)) accuracies[data_path] = accuracy accuracy_goals = { xp_dataset_name('ivy-league.csv'): .95, xp_dataset_name('xor.csv'): 1.0, xp_dataset_name('candy-data.csv'): .75, xp_dataset_name('majority-rule.csv'): 1.0 } for key in accuracy_goals: assert (accuracies[key] >= accuracy_goals[key])
def test_avr_no_ezstack_should_calc(): check_env('PATH_TO_AVR_SIZE_TOOL') PATH_TO_AVR_SIZE_TOOL = os.environ['PATH_TO_AVR_SIZE_TOOL'] arg = Arguments(size=PATH_TO_AVR_SIZE_TOOL, elf=AVR_ELF_FILE_PATH, ezstack='', mcu=AVR_MCU, maxflash=0, maxram=0) size_result = run(arg) assert size_result.ezstack_used == False assert size_result.program_size == 224.0 assert size_result.program_percent == 4.0 assert size_result.data_size == 0 assert size_result.data_percent == 0
def main(argv=None): args = argv if args is None: args = sys.argv try: if args[1] == "test": tests.run_tests() elif args[1] == "ask": src.run(args[2]) elif args[1] == "bot": bot.run_bot() else: print("Unknown command line argument") logger.error("Unknown command line argument %s", args[1]) return 1 except IndexError as err: logger.exception(err) print("Not enough arguments") return 1 except KeyError as err: logger.exception(err) print("Possible problems with JSON config. Please see logs for more information") return 1 except Psycopg2Error as err: logger.exception(err) print("Problems with database. Please, check its existence and correctness of your login and password.") return 1 except Psycopg2Warning as err: logger.exception(err) print("Sorry, we're experiencing problems with database.") return 1 except Exception as err: logger.exception(err) print("An unexpected error occurred. For more information see the log file.") return 1 return 0
def main(): parser = argparse.ArgumentParser( description='Collect airlines flight info') parser.add_argument('-r', '--route', action='append', dest='routes', help='route in format `MOW-LON`') parser.add_argument('-a', '--airline', action='append', dest='airlines', help='airlines list [Aeroflot, UralAirlines, Utair]') parser.add_argument('-j', '--jobs', type=int, default=4, dest='num_jobs', help='number of jobs') args = parser.parse_args() if args.routes is not None: routes = detect_routes(args.routes) else: routes = default_routes() if args.airlines is not None: airlines = detect_airlines(args.airlines) else: airlines = default_airlines() run(airlines, routes, args.num_jobs)
def test_stm32_ezstack_should_calc_without_ezstack(): check_env('PATH_TO_STM32_SIZE_TOOL') check_env('PATH_TO_EZSTACK') PATH_TO_STM32_SIZE_TOOL = os.environ['PATH_TO_STM32_SIZE_TOOL'] PATH_TO_EZSTACK = os.environ['PATH_TO_EZSTACK'] arg = Arguments(size=PATH_TO_STM32_SIZE_TOOL, elf=STM32_ELF_FILE_PATH, ezstack=PATH_TO_EZSTACK, mcu=STM32_MCU, maxflash=2000, maxram=100) size_result = run(arg) assert size_result.ezstack_used == False assert size_result.program_size == 1143.0 assert size_result.program_percent == 1143.0 / 2000.0 * 100.0 assert size_result.data_size == 0 assert size_result.data_percent == 0
def get_url(self): run(self.input.get())
os.environ["DEBUG"] = "1" def setup_loop(): import sys import subprocess import platform if platform.system() == "Linux": try: import uvloop except ImportError: subprocess.check_call( [sys.executable, "-m", "pip", "install", 'uvloop']) finally: import uvloop uvloop.install() if __name__ == "__main__": import os import src if os.path.isfile("config.ini"): set_env() setup_loop() src.run()
read_timeout = 10 connect_timeout = 15 def proxy_handler(method, uri, req_hdrs, s_res_start, req_pause): # can modify method, uri, req_hdrs here print uri if backend_authority: (scheme, authority, path, query, fragid) = urlsplit(uri) uri = urlunsplit((scheme, backend_authority, path, query, fragid)) def c_res_start(version, status, phrase, res_hdrs, res_pause): # can modify status, phrase, res_hdrs here res_hdrs = [(n.lower(),v.strip()) for (n,v) in res_hdrs if n.lower() not in ['connection', 'content-length', 'transfer-encoding', 'keep-alive']] res_body, res_done = s_res_start(status, phrase, res_hdrs, res_pause) # can modify res_body here return res_body, res_done c = ProxyClient(c_res_start) req_body, req_done = c.req_start(method, uri, req_hdrs, req_pause) # can modify req_body here return req_body, req_done if __name__ == "__main__": import sys port = int(sys.argv[1]) try: backend_authority = sys.argv[2] except IndexError: backend_authority = None server = SpdyServer('', port, True, 'server.crt', 'server.key', proxy_handler) run()
import src import pickle import os output_path = 'outputs' """ Next run experiments to compare Linear Programming solver and MIP solver """ #""" params = None model = 'PULP' if model == 'CPSAT': params = src.constants.get_params(int) elif model == 'MILP' or model == 'PULP': params = src.constants.get_params_v2(int) solver = src.run(params, model) #""" """ numpy model test """ """ params = src.constants.get_params(int) model = src.models.model.MIPModel(params) model.build() """
import os from src import settings, run def create(): if not os.path.exists(settings.tmp_directory): os.makedirs(settings.tmp_directory) def get_parser(): parser = argparse.ArgumentParser() parser.add_argument('link', metavar='url', nargs=1, type=valid_arg) return parser def valid_arg(args): for item in settings.sites.values(): if item in args: return args msg = 'Not valid url' raise argparse.ArgumentTypeError(msg) if __name__ == '__main__': parser = get_parser() args = parser.parse_args() create() run(*args.link)
#!/usr/bin/env python2 # TadsPad executable script import src src.run() __author__ = 'dj'
import sys from src import run if __name__ == "__main__": run(sys.argv[1:])
if __name__ == "__main__": V2I = int( input( "\nDo you want to convert video to image?[Press 1 for Yes and 0 for No (default 1)]:" ) or "1") if V2I == 1: filename = ( input(f"\nEnter video file name (default {file_names[0]} :") or file_names[0]) run( inputpath=rootpath + f"/db/input/videos/SourceDump/{filename}", fps=5, imageExt=".jpg", OutputName=jsonFileAlias, ) selection = int( input( "\nDo you want to automatically select the images? [Press 1 for Yes and 0 for No (default 0)]:" ) or "0") try: if selection == 1: retainNo = int( input( "\nHow many images do you want to retain?[Type number (default 10)]:" ) or "10") files = os.listdir(ImageCollection) for file in sample(files, len(files) - retainNo):
def test_print_6(self): # can take a lot of exprations self.assertEqual(run(r'print, "this", "that"'), 'thisthat')
def test_print_5(self): # newline token self.assertEqual(run(r"print, '\n'"), '\n')
from src import run if __name__ == '__main__': run()
import src as js_compiler file_path = input('Enter an input file name to be executed (ex: demo1): ') result, error = js_compiler.run('input/' + file_path + '.js', 'input/' + file_path + '[log].txt') if error: print(error.as_string()) else: pass # print(f'{result}')
def test_print_4(self): # if the character is after `\` sign, just output what it is. self.assertEqual(run(r"print, '\a\b\c'"), 'abc')