How to use prepare_work_dir method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_frontend.py

Source:test_frontend.py Github

copy

Full Screen

...9 assert out == 'Hello\n'10 out = tool.run_get_string(['echxo', 'Hello'])11 assert 'OCI runtime create failed' in out12def test_magic_file_io(tool):13 work_dir = prepare_work_dir('_test', ['source-a.txt'])14 out = tool.run_get_string(['cat', '_test/source-a.txt'])15 assert out == 'Source A\n'16 assert tool.upload_files == ['_test/source-a.txt']17 assert tool.download_files == []18 work_dir = prepare_work_dir('_test', ['source-b.txt'])19 out = tool.run_get_string(['cat', '_test/source-b.txt'])20 assert out == 'Source B\n'21 assert tool.upload_files == ['_test/source-b.txt']22 assert tool.download_files == []23 work_dir = prepare_work_dir('_test', ['source-a.txt'])24 tool.run(["sh", "-c", '''cat _test/source-a.txt > _test/test_a.txt'''])25 assert tool.upload_files == ['_test/source-a.txt']26 assert tool.download_files == ['_test/test_a.txt']27 time.sleep(1.5) # make sure file timestamp gets old28 tool.run(["sh", "-c", '''cat _test/source-a.txt > _test/test_a.txt'''])29 assert tool.upload_files == ['_test/source-a.txt', '_test/test_a.txt']30 assert tool.download_files == ['_test/test_a.txt']31def test_input_directory(tool):32 work_dir = prepare_work_dir('_test', ['source-b.txt', 'source-a.txt'])33 out = tool.run_get_string(['ls', '-1', '_test'])34 assert out == 'source-a.txt\nsource-b.txt\n'35 assert tool.upload_files == ['_test', '_test/source-a.txt', '_test/source-b.txt']36 assert tool.download_files == []37def test_output_mkdir(tool):38 work_dir = prepare_work_dir('_test', ['source-b.txt', 'source-a.txt'])39 tool.output_dirs = ['_test', '_test/a_test']40 out = tool.run_get_string(['ls', '-1', '_test'])41 assert out == 'a_test\n'42 assert tool.upload_files == ['_test', '_test/a_test']43 assert tool.download_files == ['_test/a_test']44def test_many_output_files(tool):45 work_dir = prepare_work_dir('_test', ['ab.zip'])46 tool.run_get_string(['unzip', '-d', '_test', '_test/ab.zip'])47 assert tool.upload_files == ['_test', '_test/ab.zip']48 assert tool.download_files == ['_test/source-a.txt', '_test/source-b.txt']49def test_many_output_files_mkdir(tool):50 work_dir = prepare_work_dir('_test', ['ab.zip'])51 tool.output_dirs = ['_test']52 tool.run_get_string(['unzip', '-d', '_test', '_test/ab.zip'])53 assert tool.upload_files == ['_test', '_test/ab.zip']54 assert tool.download_files == ['_test/source-a.txt', '_test/source-b.txt']55def test_log_stdout(tool):56 work_dir = prepare_work_dir('_test', ['ab.zip'])57 log = tool.run(['echo', 'abc'])58 assert tool.upload_files == []59 assert tool.download_files == []60 assert len(log.out_files) == 161 assert log.out_files[0].path == pathlib.Path('/dev/stdout')62 assert log.out_files[0].digest == 'edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb'63def test_log_entries(tool):64 work_dir = prepare_work_dir('_test', ['ab.zip'])65 log = tool.run(['unzip', '-d', '_test', '_test/ab.zip'])66 assert len(log.in_files) == 167 assert log.in_files[0].path == pathlib.Path().cwd() / '_test/ab.zip'68 assert log.in_files[0].digest == 'b7514875bbb128f436a607a9a1b434d928cca9bb49b3608f58e25420e7ac827d'69 assert len(log.out_files) == 370 assert log.out_files[0].path == pathlib.Path('/dev/stdout')71 assert log.out_files[0].digest == 'bf1844bc9dd9d1a3fca260f20f07b2560383e13a4537b65e7ea4304370d48d85'72 assert log.out_files[1].path == pathlib.Path().cwd() / '_test/source-a.txt'73 assert log.out_files[1].digest == '07a1a41dc6b0949c94b382890ce222005f8bf06a6bc9a2ad7d21fe577e17d2a3'74 assert log.out_files[2].path == pathlib.Path().cwd() / '_test/source-b.txt'75 assert log.out_files[2].digest == 'ad3b361a1df9bdcf159a68b122b3e21cfca69ccc13245a3df4acc996aa7414c5'76def test_output_to_tar(tool):77 work_dir = prepare_work_dir('_test', ['ab.zip'])78 tool.output_tar = (work_dir / 'output.tar').as_posix()79 log = tool.run(['unzip', '-d', '_test', '_test/ab.zip'])80 with tarfile.open(work_dir / 'output.tar') as tarball:81 tarball.extractall(path='_test')82 assert (work_dir / "_test/source-a.txt").open().read() == 'Source A\n'83 assert (work_dir / "_test/source-b.txt").open().read() == 'Source B\n'84 assert tool.upload_files == ['_test', '_test/ab.zip']85 assert tool.download_files == ['_test/source-a.txt', '_test/source-b.txt']86def test_tar_input_log(tool):87 work_dir = prepare_work_dir('_test', ['ab_zip.tar'])88 tool.input_tar = work_dir / 'ab_zip.tar'89 log = tool.run(['unzip', '-d', '_test', '_test/ab.zip'])90 assert len(log.in_files) == 191 assert log.in_files[0].path == pathlib.Path().cwd() / '_test/ab.zip'92 assert log.in_files[0].digest == 'b7514875bbb128f436a607a9a1b434d928cca9bb49b3608f58e25420e7ac827d'93 assert len(log.out_files) == 394 assert log.out_files[0].path == pathlib.Path('/dev/stdout')95 assert log.out_files[0].digest == 'bf1844bc9dd9d1a3fca260f20f07b2560383e13a4537b65e7ea4304370d48d85'96 assert log.out_files[1].path == pathlib.Path().cwd() / '_test/source-a.txt'97 assert log.out_files[1].digest == '07a1a41dc6b0949c94b382890ce222005f8bf06a6bc9a2ad7d21fe577e17d2a3'98 assert log.out_files[2].path == pathlib.Path().cwd() / '_test/source-b.txt'99 assert log.out_files[2].digest == 'ad3b361a1df9bdcf159a68b122b3e21cfca69ccc13245a3df4acc996aa7414c5'100def test_upload_file_from_dir(tool):101 # put in extra file, it should *not* get uploaded102 work_dir = prepare_work_dir('_test', ['source-a.txt', 'sub/source-c.txt'])103 tool.run_get_string(['echo', '_test/sub/source-c.txt'])104 assert tool.upload_files == ['_test/sub/source-c.txt']105 assert tool.download_files == []106def test_download_file_from_dir(tool):107 work_dir = prepare_work_dir('_test', ['sub/source-c.txt'])108 tool.run_get_string(['cp', '_test/sub/source-c.txt', '_test/sub.txt'])109 assert tool.upload_files == ['_test/sub/source-c.txt']110 assert tool.download_files == ['_test/sub.txt']111def test_download_prefix_files(tool):112 work_dir = prepare_work_dir('_test', [])113 tool.output_dirs = ['_test/fuzzed']114 r = tool.run(['sh', '-c', 'touch _test/fuzzed/a && touch _test/fuzzed/ab'])115 assert r.exit_code == 0116 assert tool.upload_files == ['_test/fuzzed']117 assert tool.download_files == ['_test/fuzzed/a', '_test/fuzzed/ab']118def test_colon_in_file_name(tool):119 work_dir = prepare_work_dir('_test', [])120 r = tool.run(['sh', '-c', 'echo Hello > "_test/file:0.txt"'])121 assert r.exit_code == 0122 assert tool.download_files == ['_test/file:0.txt']123 with open("_test/file:0.txt") as f:124 assert f.read() == 'Hello\n'125def test_entrypoint(tool):126 tool.entrypoint = "/bin/sh"127 r = tool.run_get_string(['-c', 'pwd'])128 # cincan/test image working directory is /home/appuser129 assert r == "/home/appuser\n"130 tool.entrypoint = "echo"131 r = tool.run_get_string(['hello'])132 assert r == "hello\n"133def test_interactive_mode():...

Full Screen

Full Screen

test_filtering.py

Source:test_filtering.py Github

copy

Full Screen

...7from cincan.file_tool import FileMatcher8from cincan.frontend import ToolImage9from .conftest import prepare_work_dir10def test_input_filtering(tool):11 work_dir = prepare_work_dir('_test', ['source-a.txt', 'ab.zip', 'source-b.txt'])12 out = tool.run_get_string(['ls', '-1', '_test'])13 assert out == 'ab.zip\nsource-a.txt\nsource-b.txt\n'14 assert tool.upload_files == ['_test', '_test/ab.zip', '_test/source-a.txt', '_test/source-b.txt']15 assert tool.download_files == []16 tool.input_filters = FileMatcher.parse(["_test*.zip"])17 work_dir = prepare_work_dir('_test', ['source-a.txt', 'ab.zip', 'source-b.txt'])18 out = tool.run_get_string(['ls', '-1', '_test'])19 assert out == 'ab.zip\n'20 assert tool.upload_files == ['_test/ab.zip']21 assert tool.download_files == []22 tool.input_filters = FileMatcher.parse(["_test*.txt"])23 work_dir = prepare_work_dir('_test', ['source-a.txt', 'ab.zip', 'source-b.txt'])24 out = tool.run_get_string(['ls', '-1', '_test'])25 assert out == 'source-a.txt\nsource-b.txt\n'26 assert tool.upload_files == ['_test/source-a.txt', '_test/source-b.txt']27 assert tool.download_files == []28 tool.input_filters = FileMatcher.parse(["^*.txt"])29 work_dir = prepare_work_dir('_test', ['source-a.txt', 'ab.zip', 'source-b.txt'])30 out = tool.run_get_string(['ls', '-1', '_test'])31 assert out == 'ab.zip\n'32 assert tool.upload_files == ['_test', '_test/ab.zip']33 assert tool.download_files == []34def test_explicit_in_out_files(tool):35 work_dir = prepare_work_dir('_test', ['ab.zip', 'empty.file'])36 tool.input_filters = FileMatcher.parse(['_test/ab.zip', '_test/empty.file']) # NOTHING can pass this filter!37 tool.output_filters = FileMatcher.parse(['_test/source-b.txt'])38 tool.run_get_string(['unzip', '-d', '_test', '_test/ab.zip'])39 assert tool.upload_files == []40 assert tool.download_files == []41def test_container_specific_ignore(tmp_path, tool):42 """43 Method for testing wheather .cincanignore marked files are not to be downloaded from the container or works together with user supplied filters44 """45 d = tmp_path / "tcs"46 d.mkdir()47 work_dir = prepare_work_dir('_test', ['.cincanignore'])48 relative_outdir = d.relative_to(pathlib.Path.cwd())49 # File `.test` is ignored by .cincanignore50 out = tool.run_get_string(['sh', '-c', f'cat _test/.cincanignore > .cincanignore; touch .test'])51 assert not pathlib.Path(".test").is_file()52 # check that .cincanignore is ignored as well53 assert not pathlib.Path(".cincanignore").is_file()54 # No ignore file55 out = tool.run_get_string(['sh', '-c', f'touch .test'])56 assert pathlib.Path(".test").is_file()57 os.remove(".test")58 # File `.test` is not ignored by .cincanignore (path is different) # Using tmp directory here and from this59 out = tool.run_get_string(['sh', '-c', f'cat _test/.cincanignore > .cincanignore; touch {relative_outdir}/.test'])60 assert pathlib.Path(d / ".test").is_file()61 os.remove(pathlib.Path(d / ".test"))62 # File `.test` and `.cincanignore` is not ignored by .cincanignore - --no-defaults argument used63 tool.no_defaults = True64 out = tool.run_get_string(['sh', '-c', f'echo "{relative_outdir}/.test" >> .cincanignore; touch {relative_outdir}/.test'])65 assert pathlib.Path(d / ".test").is_file()66 # Ignore file is downlaoded as well67 assert pathlib.Path(".cincanignore").is_file()68 os.remove(pathlib.Path(d / ".test"))69 os.remove(pathlib.Path(".cincanignore"))70 tool.no_defaults = False71 # File `.test` is ignored by .cincanignore - --out-filter overrides to not ignore72 tool.output_filters = FileMatcher.parse([f"{relative_outdir}/.test"])73 out = tool.run_get_string(['sh', '-c', f'echo "{relative_outdir}/.test" >> .cincanignore; touch {relative_outdir}/.test'])74 assert pathlib.Path(d / ".test").is_file()75 os.remove(pathlib.Path(d / ".test"))76 # File `.test` is ignored by .cincanignore - --outfilter used for wrong file thus file stays ignored77 tool.output_filters = FileMatcher.parse([f"{relative_outdir}/.testt"])78 out = tool.run_get_string(['sh', '-c', f'echo "{relative_outdir}/.test" >> .cincanignore; touch {relative_outdir}/.test'])79 assert not pathlib.Path(d / ".test").is_file()80 # File `.test` is not ignored by .cincanignore because --no-defaults option --outfilter ignores other file '.testagain'81 tool.no_defaults = True82 tool.output_filters = FileMatcher.parse([f"^{relative_outdir}/.testagain"])83 out = tool.run_get_string(['sh', '-c', f' echo "{relative_outdir}/.test" >> .cincanignore; touch {relative_outdir}/.test; touch {relative_outdir}/.testagain'])84 assert pathlib.Path(".cincanignore").is_file()85 assert pathlib.Path(d / ".test").is_file()86 assert not pathlib.Path(d / ".testagain").is_file()87 os.remove(pathlib.Path(".cincanignore"))88def test_container_specific_ignore_with_wildchar(tmp_path, tool):89 """90 Method for testing few wildcharacter cases with .cincanignore and filters91 """92 d = tmp_path / "tcsiww"93 d.mkdir()94 relative_outdir = d.relative_to(pathlib.Path.cwd())95 work_dir = prepare_work_dir('_test', ['.cincanignore2'])96 out = tool.run_get_string(['sh', '-c', f'cat _test/.cincanignore2 > .cincanignore; touch {relative_outdir}/.test'])97 assert not pathlib.Path(d / ".test").is_file()98 # This time, we want to include .test file by defining include filter - this overrides all filters only defined is downloaded99 tool.output_filters = FileMatcher.parse([f"{relative_outdir}/.test"])100 out = tool.run_get_string(['sh', '-c', f'cat _test/.cincanignore2 > .cincanignore; touch {relative_outdir}/.test'])...

Full Screen

Full Screen

module_utils_test.py

Source:module_utils_test.py Github

copy

Full Screen

...24 def test_prepare_work_dir_def(self):25 """26 Test default behaviour, create unique tmp dir in system temp.27 """28 path = prepare_work_dir()29 self.tempdirs.append(path)30 self.assertTrue(os.path.isdir(path))31 self.assertTrue(os.access(path, os.W_OK))32 def test_prepare_work_dir_prefix(self):33 """34 Test creation unique temp dir with 'prefix' in basename.35 """36 path = prepare_work_dir(prefix='docking-')37 self.tempdirs.append(path)38 self.assertTrue(os.path.isdir(path))39 self.assertTrue(os.path.basename(path).startswith('docking-'))40 self.assertTrue(os.access(path, os.W_OK))41 def test_prepare_work_dir_suffix(self):42 """43 Test creation unique temp dir with 'suffix' in basename.44 """45 path = prepare_work_dir(suffix='-user')46 self.tempdirs.append(path)47 self.assertTrue(os.path.isdir(path))48 self.assertTrue(os.path.basename(path).endswith('-user'))49 self.assertTrue(os.access(path, os.W_OK))50 def test_prepare_work_dir_preffix_suffix(self):51 """52 Test creation unique temp dir with 'prefix' and 'suffix' in basename.53 """54 path = prepare_work_dir(prefix='docking-', suffix='-user')55 self.tempdirs.append(path)56 self.assertTrue(os.path.isdir(path))57 self.assertTrue(os.path.basename(path).startswith('docking-'))58 self.assertTrue(os.path.basename(path).endswith('-user'))59 self.assertTrue(os.access(path, os.W_OK))60 def test_prepare_work_dir_create(self):61 """62 Test creation of unique temp dir in custom base dir63 """64 to_create = os.path.join(FILEPATH, 'tmp_user_dir')65 path = prepare_work_dir(path=to_create)66 self.tempdirs.append(to_create)67 self.assertEqual(os.path.dirname(path), to_create)68 self.assertTrue(os.path.isdir(path))69 self.assertTrue(os.access(path, os.W_OK))70 def test_prepare_work_dir_nocreate(self):71 """72 Test creation of unique temp dir in custom base dir, raise IOError73 when base dir not present74 """75 to_create = os.path.join(FILEPATH, 'tmp_user_dir')...

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 Lemoncheesecake 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