Best Python code snippet using tox_python
workspace_factory.py
Source: workspace_factory.py
1import os2import shutil3from ..utils import temporary_directory4class workspace_factory(temporary_directory):5 def __init__(self, source_space='src', prefix=''):6 super(workspace_factory, self).__init__(prefix=prefix)7 self.source_space = source_space8 def __enter__(self):9 self.temporary_directory = super(workspace_factory, self).__enter__()10 self.workspace_factory = WorkspaceFactory(self.temporary_directory, self.source_space)11 return self.workspace_factory12 def __exit__(self, exc_type, exc_value, traceback):13 super(workspace_factory, self).__exit__(exc_type, exc_value, traceback)14class WorkspaceFactory(object):15 def __init__(self, workspace, source_space='src'):16 self.workspace = workspace17 self.source_space = os.path.join(self.workspace, source_space)18 self.packages = {}19 class Package(object):20 PACKAGE_XML_TEMPLATE = """\21<?xml version="1.0"?>22<package>23 <name>{name}</name>24 <version>0.0.0</version>25 <description>26 Description for {name}27 </description>28 <maintainer email="person@email.com">Firstname Lastname</maintainer>29 <license>MIT</license>30{depends_xml}31{export_xml}32</package>33"""34 PACKAGE_XML_EXPORT_TEMPLATE = """35 <export>36 <build_type>{build_type}</build_type>37 </export>"""38 CATKIN_CMAKELISTS_TEMPLATE = """39cmake_minimum_required(VERSION 2.8.12)40project({name})41find_package(catkin REQUIRED COMPONENTS {catkin_components})42catkin_package()"""43 CMAKE_CMAKELISTS_TEMPLATE = """44cmake_minimum_required(VERSION 2.8.12)45project({name})46{find_packages}47add_custom_target(install)"""48 CMAKE_CMAKELISTS_FIND_PACKAGE_TEMPLATE = """49find_package({name})"""50 def __init__(self, name, build_type, depends, build_depends, run_depends, test_depends):51 self.name = name52 self.build_type = build_type53 self.build_depends = (build_depends or []) + (depends or [])54 self.run_depends = (run_depends or []) + (depends or [])55 self.test_depends = (test_depends or [])56 def get_package_xml(self):57 # Get dependencies58 depends_xml = '\n'.join(59 [' <buildtool_depend>{0}</buildtool_depend>'.format(self.build_type)] +60 [' <build_depend>{0}</build_depend>'.format(x) for x in self.build_depends] +61 [' <run_depend>{0}</run_depend>'.format(x) for x in self.run_depends] +62 [' <test_depend>{0}</test_depend>'.format(x) for x in self.test_depends]63 )64 # Get exports section65 if self.build_type == 'catkin':66 export_xml = ''67 else:68 export_xml = self.PACKAGE_XML_EXPORT_TEMPLATE.format(build_type=self.build_type)69 # Format the package.xml template70 return self.PACKAGE_XML_TEMPLATE.format(71 name=self.name,72 depends_xml=depends_xml,73 export_xml=export_xml)74 def get_cmakelists_txt(self):75 if self.build_type == 'catkin':76 return self.CATKIN_CMAKELISTS_TEMPLATE.format(77 name=self.name,78 catkin_components=' '.join(self.build_depends))79 if self.build_type == 'cmake':80 find_packages = '\n'.join([81 self.CMAKE_CMAKELISTS_FIND_PACKAGE_TEMPLATE.format(name=name)82 for name in self.build_depends])83 return self.CMAKE_CMAKELISTS_TEMPLATE.format(84 name=self.name,85 find_packages=find_packages)86 def add_package(self, pkg_name, package_path):87 """Copy a static package into the workspace"""88 shutil.copytree(package_path, self.source_space)89 def create_package(90 self,91 pkg_name,92 build_type='cmake',93 depends=None,94 build_depends=None,95 run_depends=None,96 test_depends=None97 ):98 """Add a package to be generated in this workspace."""99 self.packages[pkg_name] = self.Package(pkg_name, build_type, depends, build_depends, run_depends, test_depends)100 def build(self):101 """Generate workspace paths and packages."""102 cwd = os.getcwd()103 if not os.path.isdir(self.workspace):104 if os.path.exists(self.workspace):105 raise RuntimeError("Cannot build workspace in '{0}' because it is a file".format(self.workspace))106 os.makedirs(self.workspace)107 if os.path.exists(self.source_space):108 print("WARNING: source space given to WorkspaceFactory exists, clearing before build()'ing")109 self.clear()110 os.makedirs(self.source_space)111 try:112 os.chdir(self.source_space)113 for name, pkg in self.packages.items():114 pkg_dir = os.path.join(self.source_space, name)115 os.makedirs(pkg_dir)116 pkg_xml_path = os.path.join(pkg_dir, 'package.xml')117 with open(pkg_xml_path, 'w') as f:118 f.write(pkg.get_package_xml())119 cmakelists_txt_path = os.path.join(pkg_dir, 'CMakeLists.txt')120 with open(cmakelists_txt_path, 'w') as f:121 f.write(pkg.get_cmakelists_txt())122 finally:123 os.chdir(cwd)124 def clear(self):125 if os.path.exists(self.workspace):...
test_views.py
Source: test_views.py
...30 def test0006depends(self):31 '''32 Test depends.33 '''34 test_depends()35def suite():36 """37 Test Suite38 """39 test_suite = trytond.tests.test_tryton.suite()40 test_suite.addTests(41 unittest.TestLoader().loadTestsFromTestCase(TestViewDepend)42 )43 return test_suite44if __name__ == '__main__':...
test_views_depends.py
Source: test_views_depends.py
...8 def test_views(self):9 "Test all tryton views"10 from trytond.tests.test_tryton import test_view11 test_view('shopkeeper')12 def test_depends(self):13 "Test missing depends on fields"14 from trytond.tests.test_tryton import test_depends...
Check out the latest blogs from LambdaTest on this topic:
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Even though several frameworks are available in the market for automation testing, Selenium is one of the most renowned open-source frameworks used by experts due to its numerous features and benefits.
JUnit is one of the most popular unit testing frameworks in the Java ecosystem. The JUnit 5 version (also known as Jupiter) contains many exciting innovations, including support for new features in Java 8 and above. However, many developers still prefer to use the JUnit 4 framework since certain features like parallel execution with JUnit 5 are still in the experimental phase.
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!!