Best Python code snippet using avocado_python
test_pit.py
Source: test_pit.py
1import pytest2import subprocess3import string4import random5from pit import init, parse_config, clone, Pit, hash_content, add, checkout6def test_all():7 test_here()8 test_local()9 test_remote()10def test_here():11 pass12def test_local():13 pass14def test_remote():15 pass16@pytest.fixture17def tmp_dir(tmp_path_factory):18 init_dir = tmp_path_factory.mktemp('first')19 clone_dir = tmp_path_factory.mktemp('second')20 return init_dir, clone_dir21def test_init(tmp_dir):22 init_dir, _ = tmp_dir23 init(init_dir)24 with pytest.raises(Exception):25 init(init_dir)26 config_fn = init_dir / '.pit' / 'config'27 index_fn = init_dir / '.pit' / 'index'28 object_store = init_dir / '.pit' / 'objects'29 assert (init_dir / '.pit').exists()30 assert config_fn.exists()31 assert index_fn.exists()32 config = parse_config(config_fn)33 assert 'core' in config34 assert 'url' in config['core']35 assert str(object_store) == config['core']['url']36def test_clone(tmp_dir):37 init_dir, clone_dir = tmp_dir38 init(init_dir)39 clone(init_dir, clone_dir)40 cloned_pit = Pit(clone_dir)41 assert cloned_pit.object_store == init_dir / '.pit' / 'objects'42def test_add(tmp_dir):43 init_dir, _ = tmp_dir44 file = init_dir / 'file.txt'45 file.write_text('hello world!')46 init(init_dir)47 pit = Pit(init_dir)48 add(pit, file)49 assert file_in_pit(pit, file.relative_to(pit.root.parent))50def test_clone_add(tmp_dir):51 init_dir, clone_dir = tmp_dir52 init(init_dir)53 clone(init_dir, clone_dir)54 55 orig_pit = Pit(init_dir)56 clone_pit = Pit(clone_dir)57 file = random_file(init_dir, 'file')58 file2 = random_file(clone_dir, 'file2')59 add(orig_pit, file)60 add(clone_pit, file2)61 file = file.relative_to(file.parent)62 file2 = file2.relative_to(file2.parent)63 assert file_in_pit(orig_pit, file) and file_in_pit(clone_pit, file)64def test_checkout(tmp_path):65 init(tmp_path)66 pit = Pit(tmp_path)67 file = random_file(tmp_path, 'file')68 add(pit, file)69 file.unlink()70 assert not file.exists()71 assert file_in_pit(pit, file, just_index=True)72 checkout(pit, file)73 assert file.exists()74 assert file_in_pit(pit, file)75def test_hash(tmp_path):76 file = random_file(tmp_path, 'file')77 digest = hash_content(file)78 shell_digest = subprocess.run(f'shasum -a 256 {file}', shell=True, capture_output=True)79 assert digest == shell_digest.stdout.split()[0].decode()80def random_file(file_dir, name):81 file = file_dir / name82 file.write_text(''.join(random.choices(string.ascii_letters, k=42)))83 return file84def file_in_pit(pit, file, just_index=False):85 if file.is_absolute():86 file = str(file.relative_to(pit.root.parent))87 else:88 file = str(file)89 for entry in pit.index:90 _, h, fn = entry.strip().split()91 if fn == file:92 if just_index or (pit.object_store / h[:2] / h[2:]).exists():93 return True...
test_run_dir.py
Source: test_run_dir.py
1import os2import shutil3import pytest4from pymt.utils.run_dir import open_run_dir5def test_run_dir():6 init_dir = os.getcwd()7 with open_run_dir("/"):8 assert os.getcwd() == os.path.normpath("/")9 assert os.getcwd() == init_dir10def test_relative_dir():11 init_dir = os.getcwd()12 with open_run_dir(".."):13 assert os.getcwd() == os.path.abspath(os.path.join(init_dir, ".."))14 assert os.getcwd() == init_dir15def test_nested_dirs():16 init_dir = os.getcwd()17 with open_run_dir("/"):18 assert os.getcwd() == os.path.normpath("/")19 with open_run_dir("/bin"):20 assert os.getcwd() == os.path.normpath("/bin")21 assert os.getcwd() == os.path.normpath("/")22 assert os.getcwd() == init_dir23def test_nested_relative_dirs():24 init_dir = os.getcwd()25 with open_run_dir("/usr/bin"):26 assert os.getcwd() == os.path.normpath("/usr/bin")27 with open_run_dir(".."):28 assert os.getcwd() == os.path.normpath("/usr")29 assert os.getcwd() == os.path.normpath("/usr/bin")30 assert os.getcwd() == init_dir31def test_dir_does_not_exist():32 with pytest.raises(OSError):33 with open_run_dir("/not/a/real/dir"):34 pass35def test_negative_dir():36 init_dir = os.getcwd()37 with open_run_dir("/"):38 assert os.getcwd() == "/"39 with open_run_dir(".."):40 assert os.getcwd() == "/"41 assert os.getcwd() == "/"42 assert os.getcwd() == init_dir43def test_do_not_gobble_exception():44 init_dir = os.getcwd()45 try:46 with open_run_dir("/usr"):47 assert os.getcwd() == "/usr"48 raise ValueError()49 except ValueError:50 assert os.getcwd() == init_dir51 else:52 raise AssertionError("statement should not be reached")53def test_missing_dir():54 init_dir = os.getcwd()55 with pytest.raises(OSError):56 with open_run_dir("./not/a/dir"):57 pass58 assert not os.path.isdir(os.path.join(init_dir, "not/a/dir"))59def test_create_missing_dir():60 init_dir = os.getcwd()61 with open_run_dir("./not/a/dir", create=True):62 assert os.getcwd() == os.path.normpath(os.path.join(init_dir, "not/a/dir"))63 assert os.getcwd() == init_dir64 assert os.path.isdir(os.path.normpath(os.path.join(init_dir, "not/a/dir")))...
preprocessor.py
Source: preprocessor.py
1import os2def create2017ArgusFiles(init_dir):3 for cap_file in os.listdir(init_dir):4 if cap_file.endswith(".cap"):5 os.system("argus -r " + init_dir + cap_file + " -w " + init_dir + "ArgusFiles/"+cap_file.replace(".cap", ".argus"))6def create2019ArgusFiles(init_dir):7 for cap_file in os.listdir(init_dir):8 if os.path.isfile(init_dir + cap_file):9 if cap_file.endswith(".pcap"):10 os.system("argus -r " + init_dir + cap_file + " -w " + init_dir + "ArgusFiles/"+cap_file.replace(".pcap", ".argus"))11 else:12 os.system("argus -r " + init_dir + cap_file + " -w " + init_dir + "ArgusFiles/"+cap_file + ".argus")13def chooseFeatures(filename):14 listOfFeatures = []15 for line in open(filename, "r"):16 listOfFeatures.append(line.strip())17 features_string = ' '.join(listOfFeatures)18 return features_string.strip()19def createTxtFiles(init_dir):20 features_to_use = chooseFeatures("Features.txt")21 for argus_file in os.listdir(init_dir):22 if argus_file.endswith(".argus"):...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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!!