Best Python code snippet using tavern
test_pages.py
Source:test_pages.py
1import os2import unittest3from bsw.pages import Page4import bsw.includes5class TestPages(unittest.TestCase):6 def setUp(self):7 self.data_base_dir = os.path.join(os.path.dirname(__file__), "data")8 self.test_page_filename = os.path.join(self.data_base_dir,9 "pages",10 "test_page.html")11 self.test_include_path = os.path.join(self.data_base_dir,12 "templates",13 "includes",14 "test_include.html")15 self.test_template_path = os.path.join(self.data_base_dir,16 "templates",17 "test_template.html")18 def test_page_init(self):19 page = Page(self.test_page_filename)20 self.assertIsNone(page.body)21 self.assertIsNone(page.body_raw)22 self.assertIsNone(page.rendered_page)23 self.assertFalse(page.page_vars)24 self.assertEqual(page.filename, self.test_page_filename)25 def test_page_load(self):26 test_page = Page(self.test_page_filename)27 test_page.load()28 self.assertIn("My sample page", test_page.body_raw.strip())29 def test_page_extract_vars(self):30 test_page = Page(self.test_page_filename)31 test_page.load()32 test_page.extract_vars()33 self.assertIn("template", test_page.page_vars)34 self.assertEqual(test_page.page_vars["template"],35 "test_template.html")36 self.assertIn("author", test_page.page_vars)37 self.assertEqual(test_page.page_vars["author"],38 "Dave Barker")39 def test_page_strip_vars(self):40 test_page = Page(self.test_page_filename)41 test_page.load()42 test_page.extract_vars()43 test_page.strip_vars()44 self.assertNotIn("<!-- template = \"test_template.htm\" -->",45 test_page.body)46 def test_replace_includes(self):47 # Preload the includes cache48 with open(self.test_include_path, "r") as test_include_file:49 test_include_data = test_include_file.read()50 bsw.includes.include_cache["test_include.html"] = test_include_data51 test_page = Page(self.test_page_filename)52 test_page.load_and_parse()53 test_page.rendered_page = test_page.replace_includes(test_page.body)54 self.assertNotIn("<!-- include(\"test_include.html\") -->",55 test_page.rendered_page)56 self.assertIn("<h1>This is a test include</h1>",57 test_page.rendered_page)58 def test_render(self):59 # Preload the includes cache60 with open(self.test_include_path, "r") as test_include_file:61 test_include_data = test_include_file.read()62 bsw.includes.include_cache["test_include.html"] = test_include_data63 # Preload the templates cache64 with open(self.test_template_path, "r") as test_template_file:65 test_template_data = test_template_file.read()66 bsw.templates.template_cache["test_template.html"] = test_template_data67 test_page = Page(self.test_page_filename)68 test_page.load_and_parse()69 test_page.render()70 self.assertIn("My sample page",71 test_page.rendered_page)72 self.assertIn("<h1>This is a test include</h1>",73 test_page.rendered_page)74 self.assertIn("<h1>Template Header</h1>",75 test_page.rendered_page)76 self.assertIn("<h1>Template Footer</h1>",...
list_files.py
Source:list_files.py
...50 self.results1 = [self.filet, self.filep]51 self.results2 = [self.filep, self.filet]52 self.results3 = [self.fname1, self.fname2]53 self.results4 = [self.fname2, self.fname1]54 def test_include_path(self):55 """Function: test_include_path56 Description: Test with including path with file name.57 Arguments:58 """59 file_list = gen_libs.list_files(self.dir_path, include_path=True)60 self.assertTrue(61 file_list == self.results3 or file_list == self.results4)62 def test_list_files(self):63 """Function: test_list_files64 Description: Test list_files function.65 Arguments:66 """67 file_list = gen_libs.list_files(self.dir_path)68 self.assertTrue(...
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!!