How to use get_test_dir method in avocado

Best Python code snippet using avocado_python

dictfold_test.py

Source:dictfold_test.py Github

copy

Full Screen

...5import shutil6from functools import partial7from dictdir import dictfold8from dictdir import dircmds9def get_test_dir(callee_name=False):10 me_parent: Path = Path(__file__).parent11 tid = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H-%M-%S.%f')12 if callee_name:13 import inspect14 tid = f"{tid}--{inspect.stack()[1].function}"15 test_dir = me_parent / 'out' / tid16 test_dir.mkdir(parents=True, exist_ok=True)17 return test_dir18def test__traverse_simple():19 doc = {'out': {'mf.txt': "", 'tmp': {'be.txt': '123d'}}}20 actions = []21 def register(p, _, **kw):22 ntype = kw.pop('ntype')23 path_p = Path('/'.join(p))24 if ntype == 'leaf':25 cmd = f"touch {path_p}"26 elif ntype == 'node':27 cmd = f"mkdir -p {path_p}"28 else:29 raise ValueError(ntype)30 actions.append(cmd)31 dictfold.traverse_dictdir(doc, on_node=register, path='.')32 print(actions)33def test__traversex_extrasmart():34 doc = {'mf.txt': "", 'tmp': {'be.txt': '123d'}}35 out_p = get_test_dir(callee_name=True)36 on_node = partial(dictfold.node_to_action, force_write=False)37 actions: dircmds.Actions = dictfold.traverse_dictdir(38 doc, on_node=on_node, path=out_p, actions=dircmds.Actions())39 actions.exec_py_func()40 assert (out_p / 'mf.txt').exists()41 assert (out_p / 'tmp' /42 'be.txt').read_text().strip() == doc['tmp']['be.txt']43def test___scanfold():44 me_par: Path = Path(__file__).parent45 src_p = me_par.joinpath('data4tests/scanfold_pydocflow.yml')46 tdir = get_test_dir(callee_name=True)47 changes1 = dictfold.scanfold(str(src_p), dest=str(tdir))48 assert changes149 changes2 = dictfold.scanfold(str(src_p), dest=str(tdir))50 assert changes2 == 051 shutil.rmtree(str(tdir / 'tests'))52 changes3 = dictfold.scanfold(str(src_p), dest=str(tdir))53 assert 0 < changes3 < changes154 logging.info(f"test changes: {[changes1, changes2, changes3]}")55def test___scanfold_dry_script():56 me_par: Path = Path(__file__).parent57 src_p = me_par.joinpath('data4tests/scanfold_pydocflow.yml')58 changes1 = dictfold.scanfold_dry(str(src_p), dest='.').make_bash_script()59 assert changes160 assert 'test -f tests/actors/run_tests.sh' in changes161 assert 'mkdir -p tests' in changes162def test___scanfold_structure():63 doc = {64 'mf.txt': "",65 'ver.yml': "version: '1.3'",66 'tmp': {67 'be.txt': '123d'68 }69 }70 tdir = get_test_dir(callee_name=True)71 changes1 = dictfold.scanfold(doc, dest=str(tdir), root=None)72 assert changes1 == 473 assert (tdir / 'mf.txt').exists()74 assert (tdir / 'mf.txt').read_text() == ""75 assert len([it for it in (tdir / 'tmp').iterdir()]) == 176 assert (tdir / 'tmp' / 'be.txt').read_text() == '123d'77 assert (tdir / 'ver.yml').read_text() == "version: '1.3'"78 (tdir / 'mf.txt').write_text('DIRTY')79 (tdir / 'ver.yml').unlink()80 changes2 = dictfold.scanfold(doc, dest=str(tdir), root=None)81 assert changes2 == 182 assert (tdir / 'mf.txt').read_text() == "DIRTY"83 assert (tdir / 'ver.yml').read_text() == "version: '1.3'"84def test___scanfold_bash_shell():85 doc = {86 'mf.txt': "",87 'ver.yml': "version: '1.3'",88 'tmp': {89 'be.txt': '123d',90 'de.txt': '1\n\2'91 }92 }93 tdir = get_test_dir(callee_name=True)94 dictfold.scanfold(doc, dest=str(tdir), root=None, bash_shell=True)95 assert (tdir / 'mf.txt').exists()96 assert (tdir / 'ver.yml').read_text().strip() == "version: '1.3'"97 assert len([it for it in (tdir / 'tmp').iterdir()]) == 298 assert (tdir / 'tmp' / 'be.txt').read_text().strip() == '123d'99 (tdir / 'mf.txt').write_text('DIRTY')100 (tdir / 'ver.yml').unlink()101 dictfold.scanfold(doc, dest=str(tdir), root=None, bash_shell=True)102 # assert changes2 == 1103 assert (tdir / 'mf.txt').read_text() == "DIRTY"104 assert (tdir / 'ver.yml').read_text().strip() == "version: '1.3'"105def test___scanfold_bash_script():106 doc = {107 'mf.txt': "",108 'ver.yml': "version: '1.3'",109 'tmp': {110 'be.txt': '123d',111 'de.txt': '1\n\n 2\n'112 }113 }114 tdir = get_test_dir(callee_name=True)115 unfold_script = dictfold.scanfold(doc,116 dest='.',117 root=None,118 bash_script=True)119 script = "\n\n".join(120 ['#!/bin/bash', '# --- AUTOGENERATED --', unfold_script])121 (tdir / 'unfold.sh').write_text(script)122 old = os.getcwd()123 os.chdir(str(tdir))124 os.system("bash unfold.sh")125 os.chdir(old)126 # assert changes1 == 4127 assert (tdir / 'mf.txt').exists()128 assert (tdir / 'ver.yml').read_text().strip() == "version: '1.3'"...

Full Screen

Full Screen

test_qtools_submitter.py

Source:test_qtools_submitter.py Github

copy

Full Screen

...10class Test(unittest.TestCase):11 def test_main(self):12 commands = ['date', 'echo testing PBS']13 job_name = 'test_qtools_submitter'14 submit_sh = '%s/%s.sh' % (tests.get_test_dir(), job_name)15 sub = Submitter(queue_type='PBS', sh_file=submit_sh,16 command_list=commands,17 job_name=job_name)18 job_id = sub.write_sh(submit=True, nodes=1, ppn=16,19 queue='home-yeo', walltime='0:01:00')20 true_result_string = '''#!/bin/sh21#PBS -N test_qtools_submitter22#PBS -o %s/test_qtools_submitter.sh.out23#PBS -e %s/test_qtools_submitter.sh.err24#PBS -V25#PBS -l walltime=0:01:0026#PBS -l nodes=1:ppn=1627#PBS -A yeo-group28#PBS -q home-yeo29# Go to the directory from which the script was called30cd $PBS_O_WORKDIR31date32echo testing PBS33''' % (tests.get_test_dir(), tests.get_test_dir())34 true_result = true_result_string.split('\n')35 # with open(submit_sh) as f:36 # for x in f.readlines():37 # print x,38 for true, test in zip(true_result, open(submit_sh)):39 self.assertEqual(true.strip().split(), test.strip().split())40 # Make sure the job ID is a single (potentially multi-digit) integer41 self.assertRegexpMatches(job_id, '^\d+$')42 subprocess.Popen(["qdel", job_id],43 stdout=PIPE)44 def test_wait_for_pbs(self):45 commands = ['date', 'echo testing PBS']46 job_name = 'test_qtools_submitter_wait_for_pbs'47 submit_sh = '%s/%s.sh' % (tests.get_test_dir(), job_name)48 sub = Submitter(queue_type='PBS', sh_file= submit_sh,49 command_list=commands,50 job_name=job_name, wait_for=['11111'])51 job_id = sub.write_sh(submit=True, nodes=1, ppn=16,52 queue='home-yeo', walltime='0:01:00')53 true_result_string = '''#!/bin/sh54#PBS -N test_qtools_submitter_wait_for_pbs55#PBS -o %s/test_qtools_submitter_wait_for_pbs.sh.out56#PBS -e %s/test_qtools_submitter_wait_for_pbs.sh.err57#PBS -V58#PBS -l walltime=0:01:0059#PBS -l nodes=1:ppn=1660#PBS -A yeo-group61#PBS -q home-yeo62#PBS -W depend=afterok:1111163# Go to the directory from which the script was called64cd $PBS_O_WORKDIR65date66echo testing PBS67''' % (tests.get_test_dir(), tests.get_test_dir())68 true_result = true_result_string.split('\n')69 # with open(submit_sh) as f:70 # for x in f.readlines():71 # print x,72 for true, test in zip(true_result, open(submit_sh)):73 self.assertEqual(true.strip().split(), test.strip().split())74 # Make sure the job ID is a single (potentially multi-digit) integer75 self.assertRegexpMatches(job_id, '^\d+$')76 subprocess.Popen(["qdel", job_id],77 stdout=PIPE)78 def test_wait_for_array_pbs(self):79 commands = ['date', 'echo testing PBS']80 job_name = 'test_qtools_submitter_wait_for_pbs'81 submit_sh = '%s/%s.sh' % (tests.get_test_dir(), job_name)82 sub = Submitter(queue_type='PBS', sh_file= submit_sh,83 command_list=commands,84 job_name=job_name, wait_for_array=['11111'])85 job_id = sub.write_sh(submit=True, nodes=1, ppn=16,86 queue='home-yeo', walltime='0:01:00')87 true_result_string = '''#!/bin/sh88#PBS -N test_qtools_submitter_wait_for_pbs89#PBS -o %s/test_qtools_submitter_wait_for_pbs.sh.out90#PBS -e %s/test_qtools_submitter_wait_for_pbs.sh.err91#PBS -V92#PBS -l walltime=0:01:0093#PBS -l nodes=1:ppn=1694#PBS -A yeo-group95#PBS -q home-yeo96#PBS -W depend=afterokarray:1111197# Go to the directory from which the script was called98cd $PBS_O_WORKDIR99date100echo testing PBS101''' % (tests.get_test_dir(), tests.get_test_dir())102 true_result = true_result_string.split('\n')103 # with open(submit_sh) as f:104 # for x in f.readlines():105 # print x,106 for true, test in zip(true_result, open(submit_sh)):107 self.assertEqual(true.strip().split(), test.strip().split())108 # Make sure the job ID is a single (potentially multi-digit) integer109 self.assertRegexpMatches(job_id, '^\d+$')110 subprocess.Popen(["qdel", job_id],111 stdout=PIPE)112if __name__ == "__main__":113 #import sys;sys.argv = ['', 'Test.test_main']...

Full Screen

Full Screen

setup_test.py

Source:setup_test.py Github

copy

Full Screen

...22 file_path = os.path.dirname(__file__)23 out = os.path.dirname(file_path) # go up one time24 return out25 @classmethod26 def get_test_dir(cls) -> str:27 project_dir = cls.get_project_dir()28 out = os.path.join(project_dir, cls.TEST_DIR)29 return out30 @classmethod31 def get_test_path(cls, relative_path) -> str:32 return os.path.join(cls.get_test_dir(), relative_path)33 @classmethod34 def ensure_test_dir(cls) -> str:35 return cls.ensure_dir(cls.get_test_dir())36 @classmethod37 def ensure_clean_test_dir(cls) -> str:38 return cls.ensure_clean_dir(cls.get_test_dir())39 @classmethod40 def ensure_dir(cls, dirpath) -> str:41 exists = os.path.exists(dirpath)42 if exists and not os.path.isdir(dirpath):43 raise NotADirectoryError(dirpath)44 if not exists:45 os.makedirs(dirpath)46 return dirpath47 @classmethod48 def ensure_clean_dir(cls, dirpath) -> str:49 if not os.path.exists(dirpath):50 cls.ensure_dir(dirpath)51 else:52 cls.clean_dir_recursively(dirpath)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful