Best Python code snippet using slash
cli_test.py
Source:cli_test.py
...7 assert Newdle.query.count() == 18 cli_runner.invoke(cleanup_newdles, [])9 assert Newdle.query.count() == 110def test_cleanup_newdles_final_date_disabled(cli_runner, dummy_newdle, override_config):11 override_config(LAST_ACTIVITY_CLEANUP_DELAY=90, FINAL_DATE_CLEANUP_DELAY=None)12 days = timedelta(days=current_app.config['LAST_ACTIVITY_CLEANUP_DELAY'] - 10)13 dummy_newdle.last_update = datetime.utcnow() - days14 dummy_newdle.final_dt = datetime.utcnow() - timedelta(days=60)15 db.session.commit()16 assert Newdle.query.count() == 117 cli_runner.invoke(cleanup_newdles, [])18 assert Newdle.query.count() == 119def test_cleanup_newdles_uncompleted_tasks(cli_runner, dummy_newdle, override_config):20 override_config(LAST_ACTIVITY_CLEANUP_DELAY=90, FINAL_DATE_CLEANUP_DELAY=30)21 days = timedelta(days=current_app.config['LAST_ACTIVITY_CLEANUP_DELAY'] + 1)22 dummy_newdle.last_update = datetime.utcnow() - days23 db.session.commit()24 assert Newdle.query.count() == 125 cli_runner.invoke(cleanup_newdles, [])26 assert Newdle.query.count() == 027def test_cleanup_newdles_non_fitting_incomplete_tasks(28 cli_runner, dummy_newdle, override_config29):30 override_config(LAST_ACTIVITY_CLEANUP_DELAY=90, FINAL_DATE_CLEANUP_DELAY=30)31 days = timedelta(days=current_app.config['LAST_ACTIVITY_CLEANUP_DELAY'] - 10)32 dummy_newdle.last_update = datetime.utcnow() - days33 db.session.commit()34 assert Newdle.query.count() == 135 cli_runner.invoke(cleanup_newdles, [])36 assert Newdle.query.count() == 137def test_cleanup_deleted_newdles_tasks(cli_runner, dummy_newdle, override_config):38 override_config(39 LAST_ACTIVITY_CLEANUP_DELAY=90,40 FINAL_DATE_CLEANUP_DELAY=30,41 DELETED_CLEANUP_DELAY=15,42 )43 days = timedelta(days=current_app.config['DELETED_CLEANUP_DELAY'] + 1)44 dummy_newdle.deletion_dt = datetime.utcnow() - days45 db.session.commit()46 assert Newdle.query.count() == 147 cli_runner.invoke(cleanup_newdles, [])48 assert Newdle.query.count() == 049def test_cleanup_newdles_non_fitting_deleted_tasks(50 cli_runner, dummy_newdle, override_config51):52 override_config(53 LAST_ACTIVITY_CLEANUP_DELAY=90,54 FINAL_DATE_CLEANUP_DELAY=30,55 DELETED_CLEANUP_DELAY=15,56 )57 days = timedelta(days=current_app.config['DELETED_CLEANUP_DELAY'] - 10)58 dummy_newdle.last_update = datetime.utcnow() - days59 db.session.commit()60 assert Newdle.query.count() == 161 cli_runner.invoke(cleanup_newdles, [])62 assert Newdle.query.count() == 163def test_cleanup_newdles_final_tasks(cli_runner, dummy_newdle, override_config):64 override_config(LAST_ACTIVITY_CLEANUP_DELAY=90, FINAL_DATE_CLEANUP_DELAY=30)65 days = timedelta(days=current_app.config['FINAL_DATE_CLEANUP_DELAY'] + 1)66 days_upd = timedelta(days=current_app.config['LAST_ACTIVITY_CLEANUP_DELAY'] + 1)67 dummy_newdle.final_dt = datetime.utcnow() - days68 dummy_newdle.last_update = datetime.utcnow() - days_upd69 db.session.commit()70 assert Newdle.query.count() == 171 cli_runner.invoke(cleanup_newdles, [])72 assert Newdle.query.count() == 073def test_cleanup_newdles_non_fitting_final_tasks(74 cli_runner, dummy_newdle, override_config75):76 override_config(LAST_ACTIVITY_CLEANUP_DELAY=90, FINAL_DATE_CLEANUP_DELAY=30)77 days = timedelta(days=current_app.config['FINAL_DATE_CLEANUP_DELAY'] - 5)78 dummy_newdle.final_dt = datetime.utcnow() - days79 db.session.commit()80 assert Newdle.query.count() == 181 cli_runner.invoke(cleanup_newdles, [])82 assert Newdle.query.count() == 183def test_cleanup_newdles_multiple_entries_final_task(84 cli_runner, create_newdle, override_config85):86 override_config(LAST_ACTIVITY_CLEANUP_DELAY=90, FINAL_DATE_CLEANUP_DELAY=30)87 newdle_1 = create_newdle(1)88 newdle_2 = create_newdle(2)89 create_newdle(3)90 assert Newdle.query.count() == 391 days = timedelta(days=current_app.config['FINAL_DATE_CLEANUP_DELAY'] + 1)92 days_upd = timedelta(days=current_app.config['LAST_ACTIVITY_CLEANUP_DELAY'] + 1)93 newdle_1.final_dt = datetime.utcnow() - days94 newdle_1.last_update = datetime.utcnow() - days_upd95 days_upd = timedelta(days=current_app.config['LAST_ACTIVITY_CLEANUP_DELAY'] - 5)96 newdle_2.last_update = datetime.utcnow() - days_upd97 db.session.commit()98 cli_runner.invoke(cleanup_newdles, [])...
test_vggtransformer.py
Source:test_vggtransformer.py
...19 get_dummy_input,20)21class VGGTransformerModelTest_mid(TestFairseqEncoderDecoderModelBase):22 def setUp(self):23 def override_config(args):24 """25 vggtrasformer_1 use 14 layers of transformer,26 for testing purpose, it is too expensive. For fast turn-around27 test, reduce the number of layers to 3.28 """29 args.transformer_enc_config = (30 "((1024, 16, 4096, True, 0.15, 0.15, 0.15),) * 3"31 )32 super().setUp()33 extra_args_setter = [vggtransformer_1, override_config]34 self.setUpModel(VGGTransformerModel, extra_args_setter)35 self.setUpInput(get_dummy_input(T=50, D=80, B=5, K=DEFAULT_TEST_VOCAB_SIZE))36class VGGTransformerModelTest_big(TestFairseqEncoderDecoderModelBase):37 def setUp(self):38 def override_config(args):39 """40 vggtrasformer_2 use 16 layers of transformer,41 for testing purpose, it is too expensive. For fast turn-around42 test, reduce the number of layers to 3.43 """44 args.transformer_enc_config = (45 "((1024, 16, 4096, True, 0.15, 0.15, 0.15),) * 3"46 )47 super().setUp()48 extra_args_setter = [vggtransformer_2, override_config]49 self.setUpModel(VGGTransformerModel, extra_args_setter)50 self.setUpInput(get_dummy_input(T=50, D=80, B=5, K=DEFAULT_TEST_VOCAB_SIZE))51class VGGTransformerModelTest_base(TestFairseqEncoderDecoderModelBase):52 def setUp(self):53 def override_config(args):54 """55 vggtrasformer_base use 12 layers of transformer,56 for testing purpose, it is too expensive. For fast turn-around57 test, reduce the number of layers to 3.58 """59 args.transformer_enc_config = (60 "((512, 8, 2048, True, 0.15, 0.15, 0.15),) * 3"61 )62 super().setUp()63 extra_args_setter = [vggtransformer_base, override_config]64 self.setUpModel(VGGTransformerModel, extra_args_setter)65 self.setUpInput(get_dummy_input(T=50, D=80, B=5, K=DEFAULT_TEST_VOCAB_SIZE))66class VGGTransformerEncoderTest(TestFairseqEncoderBase):67 def setUp(self):...
loader.py
Source:loader.py
...25 self.load_model_from_files()26 # Override config from args, if any27 config_list = self.model.args.config28 if config_list is not None and len(config_list):29 self.override_config(config_list)30 # Validate tasks after full loading process31 self.validate_tasks()32 def load_model_from_files(self):33 # Add built-in config items34 root = self.model.args.root.resolve()35 for name, value in {36 NmkRootConfig.PYTHON_PATH: [],37 NmkRootConfig.BASE_DIR: "", # Useless while directly referenced (must identify current project file parent dir)38 NmkRootConfig.ROOT_DIR: root,39 NmkRootConfig.CACHE_DIR: root / ".nmk",40 NmkRootConfig.PROJECT_DIR: "", # Will be updated as soon as initial project is loaded41 NmkRootConfig.PROJECT_FILES: [], # Will be updated as soon as files are loaded42 NmkRootConfig.ENV: {k: v for k, v in os.environ.items()},43 }.items():44 self.model.add_config(name, None, value)45 # Init recursive files loading loop46 NmkModelFile(self.model.args.project, self.repo_cache, self.model, [])47 # Refresh project files list48 NmkLogger.debug(f"Updating {NmkRootConfig.PROJECT_FILES} now that all files are loaded")49 self.model.config[NmkRootConfig.PROJECT_FILES] = NmkStaticConfig(NmkRootConfig.PROJECT_FILES, self.model, None, list(self.model.files.keys()))50 def override_config(self, config_list: List[str]):51 # Iterate on config52 for config_str in config_list:53 override_config = {}54 # Json fragment?55 if config_str[0] == "{":56 # Load json fragment from config arg, if any57 try:58 override_config = json.loads(config_str)59 except Exception as e:60 raise Exception(f"Invalid Json fragment for --config option: {e}")61 # Single config string?62 else:63 m = CONFIG_STRING_PATTERN.match(config_str)64 assert m is not None, f"Config option is neither a json object nor a K=V string: {config_str}"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!