How to use test_links method in avocado

Best Python code snippet using avocado_python

tar_archive_test.py

Source:tar_archive_test.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright (c) 2012 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Unit tests for tar_archive.py."""6import os7import sys8import tarfile9import unittest10from build_tools import tar_archive11class TestTarArchive(unittest.TestCase):12 """This class tests basic functionality of the tar_archive package"""13 def setUp(self):14 self.archive = tar_archive.TarArchive()15 def ValidateTableOfContents(self, archive, path_filter=None):16 '''Helper method to validate an archive table of contents.17 The test table of contents file has these entries (from tar tv):18 drwxr-xr-x test_links/19 drwxr-xr-x test_links/test_dir/20 lrwxr-xr-x test_links/test_dir_slnk -> test_dir21 -rw-r--r-- test_links/test_hlnk_file_dst1.txt22 hrw-r--r-- test_links/test_hlnk_file_dst2.txt link to \23 test_links/test_hlnk_file_dst1.txt24 hrw-r--r-- test_links/test_hlnk_file_src.txt link to \25 test_links/test_hlnk_file_dst1.txt26 lrwxr-xr-x test_links/test_slnk_file_dst.txt -> test_slnk_file_src.txt27 -rw-r--r-- test_links/test_slnk_file_src.txt28 -rw-r--r-- test_links/test_dir/test_file.txt29 hrw-r--r-- test_links/test_dir/test_hlnk_file_dst3.txt \30 test_links/test_hlnk_file_dst1.txt31 lrwxr-xr-x test_links/test_dir/test_slnk_file_dst2.txt -> \32 ../test_slnk_file_src.txt33 Args:34 archive: The TarArchive object under test.35 '''36 if not path_filter:37 path_filter = lambda p: os.path.join('test_links', p)38 self.assertEqual(3, len(archive.files))39 self.assertTrue(path_filter('test_slnk_file_src.txt') in archive.files)40 self.assertTrue(path_filter(os.path.join('test_dir', 'test_file.txt')) in41 archive.files)42 for file in archive.files:43 self.assertFalse('_dir' in os.path.basename(file))44 self.assertTrue(path_filter(os.path.join('test_dir', 'test_file.txt')) in45 archive.files)46 self.assertEqual(2, len(archive.dirs))47 self.assertTrue(path_filter('test_dir') in archive.dirs)48 for dir in archive.dirs:49 self.assertFalse('slnk' in dir)50 self.assertFalse('.txt' in dir)51 self.assertFalse(dir in archive.files)52 self.assertFalse(dir in archive.symlinks.keys())53 self.assertEqual(3, len(archive.symlinks))54 self.assertTrue(path_filter('test_dir_slnk') in archive.symlinks)55 self.assertTrue(path_filter('test_slnk_file_dst.txt') in archive.symlinks)56 for path, target in archive.symlinks.items():57 self.assertFalse(path in archive.files)58 self.assertFalse(path in archive.dirs)59 # Make sure the target exists in either |archive.files| or60 # |archive.dirs|. The target path in the archive is relative to the61 #source file's path.62 target_path = os.path.normpath(os.path.join(63 os.path.dirname(path), target))64 self.assertTrue((target_path in archive.files) or65 (target_path in archive.dirs))66 self.assertEqual(3, len(archive.links))67 # There is no "source" file for hard links like there is for a symbolic68 # link, so there it's possible that the hlnk_src file is in the69 # |archive.links| set, which is OK as long as one of the hlnk files is70 # in the |archive.files| set. Make sure that only hlnk files are in the71 # |archive.links| list.72 for path, target in archive.links.items():73 self.assertTrue('test_hlnk_file' in path)74 self.assertFalse(path in archive.files)75 self.assertFalse(path in archive.dirs)76 self.assertTrue(target in archive.files)77 self.assertFalse(target in archive.dirs)78 def testConstructor(self):79 """Test default constructor."""80 self.assertEqual(0, len(self.archive.files))81 self.assertEqual(0, len(self.archive.dirs))82 self.assertEqual(0, len(self.archive.symlinks))83 self.assertEqual(0, len(self.archive.links))84 def testFromTarball(self):85 """Testing the TarArchive when using a tarball"""86 # Use a known test archive to validate the TOC entries.87 self.archive.InitWithTarFile(os.path.join('build_tools',88 'tests',89 'test_links.tgz'))90 self.ValidateTableOfContents(self.archive)91 def testFromTarballBadFile(self):92 """Testing the TarArchive when using a bad tarball"""93 self.assertRaises(OSError,94 self.archive.InitWithTarFile,95 'nosuchfile')96 self.assertRaises(tarfile.ReadError,97 self.archive.InitWithTarFile,98 os.path.join('build_tools',99 'tests',100 'test_links.tgz.manifest'))101 def testFromManifest(self):102 """Testing the TarArchive when using a manifest file"""103 # Use a known test manifest to validate the TOC entries.104 # The test manifest file is the output of tar -tv on the tarball used in105 # testGetArchiveTableOfContents().106 self.archive.InitWithManifest(os.path.join('build_tools',107 'tests',108 'test_links.tgz.manifest'))109 self.ValidateTableOfContents(self.archive)110 def testFromManifestBadFile(self):111 """Testing the TarArchive when using a bad manifest file"""112 self.assertRaises(OSError, self.archive.InitWithManifest, 'nosuchfile')113 def testPathFilter(self):114 """Testing the TarArchive when applying a path filter"""115 def StripTestLinks(tar_path):116 # Strip off the leading 'test_links/' path component.117 pos = tar_path.find('test_links/')118 if pos >= 0:119 return os.path.normpath(tar_path[len('test_links/'):])120 else:121 return os.path.normpath(tar_path)122 self.archive.path_filter = StripTestLinks123 self.archive.InitWithTarFile(os.path.join('build_tools',124 'tests',125 'test_links.tgz'))126 self.ValidateTableOfContents(self.archive, path_filter=lambda p: p)127 self.archive.InitWithManifest(os.path.join('build_tools',128 'tests',129 'test_links.tgz.manifest'))130 self.ValidateTableOfContents(self.archive, path_filter=lambda p: p)131 def testPathFilterNone(self):132 """Testing the TarArchive when applying a None path filter"""133 # Verify that the paths in the |archive| object have the tar-style '/'134 # separator.135 def ValidateTarStylePaths(archive):136 def AssertTarPath(iterable):137 for i in iterable:138 self.assertTrue(len(i.split('/')) > 0)139 self.assertEqual(3, len(archive.files))140 AssertTarPath(archive.files)141 self.assertEqual(2, len(archive.dirs))142 AssertTarPath(archive.dirs)143 self.assertEqual(3, len(archive.symlinks))144 AssertTarPath(archive.symlinks.keys())145 self.assertEqual(3, len(archive.links))146 AssertTarPath(archive.links.keys())147 self.archive.path_filter = None148 self.archive.InitWithTarFile(os.path.join('build_tools',149 'tests',150 'test_links.tgz'))151 ValidateTarStylePaths(self.archive)152 self.archive.InitWithManifest(os.path.join('build_tools',153 'tests',154 'test_links.tgz.manifest'))155 ValidateTarStylePaths(self.archive)156 def testDeletePathFilter(self):157 # Note: due to the use of del() here, self.assertRaises() can't be used.158 # Also, the with self.assertRaises() idiom is not in python 2.6 so it159 # can't be used either.160 try:161 del(self.archive.path_filter)162 except tar_archive.Error:163 pass164 else:165 raise166def RunTests():167 suite = unittest.TestLoader().loadTestsFromTestCase(TestTarArchive)168 result = unittest.TextTestRunner(verbosity=2).run(suite)169 return int(not result.wasSuccessful())170if __name__ == '__main__':...

Full Screen

Full Screen

setcitation.py

Source:setcitation.py Github

copy

Full Screen

1from popit.models import *2def set_citation_person():3 test_links = {4 "url": "http://sinarproject.org",5 "note": "this is the note for %s"6 }7 person = Person.objects.language("en").get(id="8497ba86-7485-42d2-9596-2ab14520f1f4")8 for field in person._meta.fields:9 field_name = field.attname10 if field_name == "id":11 continue12 if getattr(person, field_name):13 person.add_citation(field_name, test_links["url"], test_links["note"] % field_name)14 for field_name in person._translated_field_names:15 if field_name == "id" or field_name == "master_id" or field_name == "master":16 continue17 if getattr(person, field_name):18 person.add_citation(field_name, test_links["url"], test_links["note"] % field_name)19def set_citation_person_contact_details():20 test_links = {21 "url": "http://sinarproject.org",22 "note": "this is the note for %s"23 }24 contact_detail = ContactDetail.objects.language("en").get(id="78a35135-52e3-4af9-8c32-ea3f557354fd")25 for field in contact_detail._meta.fields:26 field_name = field.attname27 if field_name == id:28 continue29 if field_name == "object_id" or field_name == "content_object":30 continue31 contact_detail.add_citation(field_name, test_links["url"], test_links["note"] % field_name)32 for field_name in contact_detail._translated_field_names:33 if field_name == id or field_name == "master_id":34 continue35 if field_name == "object_id" or field_name == "content_object":36 continue37 if field_name == "master":38 continue39 contact_detail.add_citation(field_name, test_links["url"], test_links["note"] % field_name)40def set_citation_person_othername():41 test_links = {42 "url": "http://sinarproject.org",43 "note": "this is the note for %s"44 }45 other_name = OtherName.objects.language("en").get(id="cf93e73f-91b6-4fad-bf76-0782c80297a8")46 for field in other_name._meta.fields:47 field_name = field.attname48 if field_name == id:49 continue50 if field_name == "object_id" or field_name == "content_object":51 continue52 other_name.add_citation(field_name, test_links["url"], test_links["note"] % field_name)53 for field_name in other_name._translated_field_names:54 if field_name == id or field_name == "master_id":55 continue56 if field_name == "object_id" or field_name == "content_object":57 continue58 if field_name == "master":59 continue60 other_name.add_citation(field_name, test_links["url"], test_links["note"] % field_name)61def set_citation_person_identifier():62 test_links = {63 "url": "http://sinarproject.org",64 "note": "this is the note for %s"65 }66 identifier = Identifier.objects.language("en").get(id="2d3b8d2c-77b8-42f5-ac62-3e83d4408bda")67 for field in identifier._meta.fields:68 field_name = field.attname69 if field_name == id:70 continue71 if field_name == "object_id" or field_name == "content_object":72 continue73 identifier.add_citation(field_name, test_links["url"], test_links["note"] % field_name)74 for field_name in identifier._translated_field_names:75 if field_name == id or field_name == "master_id":76 continue77 if field_name == "object_id" or field_name == "content_object":78 continue79 if field_name == "master":80 continue81 identifier.add_citation(field_name, test_links["url"], test_links["note"] % field_name)82def set_citation_organization():83 test_links = {84 "url": "http://sinarproject.org",85 "note": "this is the note for %s"86 }87 organization = Organization.objects.language("en").get(id="3d62d9ea-0600-4f29-8ce6-f7720fd49aa3")88 for field in organization._meta.fields:89 field_name = field.attname90 if field_name == id:91 continue92 if field_name == "object_id" or field_name == "content_object":93 continue94 organization.add_citation(field_name, test_links["url"], test_links["note"] % field_name)95 for field_name in organization._translated_field_names:96 if field_name == id or field_name == "master_id":97 continue98 if field_name == "object_id" or field_name == "content_object":99 continue100 if field_name == "master":101 continue102 organization.add_citation(field_name, test_links["url"], test_links["note"] % field_name)103def set_citation_organization_othername():104 test_links = {105 "url": "http://sinarproject.org",106 "note": "this is the note for %s"107 }108 other_name = OtherName.objects.language("en").get(id="aee39ddd-6785-4a36-9781-8e745c6359b7")109 for field in other_name._meta.fields:110 field_name = field.attname111 if field_name == id:112 continue113 if field_name == "object_id" or field_name == "content_object":114 continue115 other_name.add_citation(field_name, test_links["url"], test_links["note"] % field_name)116 for field_name in other_name._translated_field_names:117 if field_name == id or field_name == "master_id":118 continue119 if field_name == "object_id" or field_name == "content_object":120 continue121 if field_name == "master":122 continue123 other_name.add_citation(field_name, test_links["url"], test_links["note"] % field_name)124def set_citation_post():125 test_links = {126 "url": "http://sinarproject.org",127 "note": "this is the note for %s"128 }129 post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")130 for field in post._meta.fields:131 field_name = field.attname132 if field_name == id:133 continue134 if field_name == "object_id" or field_name == "content_object":135 continue136 post.add_citation(field_name, test_links["url"], test_links["note"] % field_name)137 for field_name in post._translated_field_names:138 if field_name == id or field_name == "master_id":139 continue140 if field_name == "object_id" or field_name == "content_object":141 continue142 if field_name == "master":143 continue144 post.add_citation(field_name, test_links["url"], test_links["note"] % field_name)145def set_citation_membership():146 test_links = {147 "url": "http://sinarproject.org",148 "note": "this is the note for %s"149 }150 membership = Membership.objects.language("en").get(id="b351cdc2-6961-4fc7-9d61-08fca66e1d44")151 for field in membership._meta.fields:152 field_name = field.attname153 if field_name == id:154 continue155 if field_name == "object_id" or field_name == "content_object":156 continue157 membership.add_citation(field_name, test_links["url"], test_links["note"] % field_name)158 for field_name in membership._translated_field_names:159 if field_name == id or field_name == "master_id":160 continue161 if field_name == "object_id" or field_name == "content_object":162 continue163 if field_name == "master":164 continue...

Full Screen

Full Screen

lesson6_step3!_parametrize_3.py

Source:lesson6_step3!_parametrize_3.py Github

copy

Full Screen

1# $ pytest -s -v lesson6_step3\!_parametrize_3.py2import time3import math4import pytest5from selenium import webdriver6from selenium.webdriver.common.by import By7test_links = []8with open("links_for_test") as f_:9 test_links = f_.readlines()10print("test_links: ", test_links)11# test_links: ['https://stepik.org/lesson/236895/step/1\n', 'https://stepik.org/lesson/236896/step/1\n', 'https://stepik.org/lesson/236897/step/1\n', 'https://stepik.org/lesson/236898/step/1\n', 'https://stepik.org/lesson/236899/step/1\n', 'https://stepik.org/lesson/236903/step/1\n', 'https://stepik.org/lesson/236904/step/1\n', 'https://stepik.org/lesson/236905/step/1']12test_links = [line.rstrip() for line in test_links]13@pytest.fixture(scope="function")14def browser():15 print("\nstart browser for test..")16 browser = webdriver.Chrome()17 browser.implicitly_wait(5)18 yield browser19 print("\nquit browser..")20 browser.quit()21@pytest.mark.parametrize('url', test_links)22def test_selenium_3_6_3(browser, url):23 link = "{}".format(url)24 browser.get(link)25 browser.implicitly_wait(5)26 browser.find_element(By.CSS_SELECTOR, ".textarea").send_keys(str(math.log(int(time.time()))))27 browser.find_element(By.CLASS_NAME, "submit-submission").click()28 ans = browser.find_element(By.CLASS_NAME, "smart-hints__hint").text29 try:30 assert "Correct!" in ans31 except:32 with open("3_6_3_test_Errors.log", "a") as f:33 f.write(ans)...

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