How to use test_dependency method in molecule

Best Python code snippet using molecule_python

interface.py

Source:interface.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""Helper for writing files that contain dependency information."""3import abc4import io5import string6class DependencyFileWriter(object):7 """Base class for dependency file writers."""8 def __init__(9 self, l2tdevtools_path, project_definition, dependency_helper):10 """Initializes a dependency file writer.11 Args:12 l2tdevtools_path (str): path to l2tdevtools.13 project_definition (ProjectDefinition): project definition.14 dependency_helper (DependencyHelper): dependency helper.15 """16 super(DependencyFileWriter, self).__init__()17 self._dependency_helper = dependency_helper18 self._l2tdevtools_path = l2tdevtools_path19 self._project_definition = project_definition20 def _GenerateFromTemplate(self, template_filename, template_mappings):21 """Generates file context based on a template file.22 Args:23 template_filename (str): path of the template file.24 template_mappings (dict[str, str]): template mappings, where the key25 maps to the name of a template variable.26 Returns:27 str: output based on the template string.28 Raises:29 RuntimeError: if the template cannot be formatted.30 """31 template_string = self._ReadTemplateFile(template_filename)32 try:33 return template_string.substitute(template_mappings)34 except (KeyError, ValueError) as exception:35 raise RuntimeError(36 'Unable to format template: {0:s} with error: {1!s}'.format(37 template_filename, exception))38 def _GetDPKGPythonDependencies(self):39 """Retrieves DPKG Python dependencies.40 Returns:41 list[str]: DPKG package names of Python dependencies.42 """43 return self._dependency_helper.GetDPKGDepends(exclude_version=True)44 def _GetDPKGTestDependencies(self, python_dependencies):45 """Retrieves DPKG test dependencies.46 Args:47 python_dependencies (list[str]): DPKG package names of Python48 dependencies.49 Returns:50 list[str]: DPKG package names of test dependencies.51 """52 test_dependencies = self._dependency_helper.GetDPKGDepends(53 exclude_version=True, test_dependencies=True)54 # TODO: replace by test_dependencies.ini or dev_dependencies.ini or equiv.55 test_dependencies.extend(['python3-distutils', 'python3-setuptools'])56 return [57 test_dependency for test_dependency in sorted(test_dependencies)58 if test_dependency not in python_dependencies]59 def _GetPyPIPythonDependencies(self, exclude_version=False):60 """Retrieves PyPI Python dependencies.61 Args:62 exclude_version (Optional[bool]): True if the version should be excluded63 from the dependency definitions.64 Returns:65 list[str]: PyPI package names of Python dependencies.66 """67 return self._dependency_helper.GetInstallRequires(68 exclude_version=exclude_version)69 def _GetPyPITestDependencies(70 self, python_dependencies, exclude_version=False):71 """Retrieves PyPI test dependencies.72 Args:73 python_dependencies (list[str]): PyPI package names of Python74 dependencies.75 exclude_version (Optional[bool]): True if the version should be excluded76 from the dependency definitions.77 Returns:78 list[str]: PyPI package names of test dependencies.79 """80 test_dependencies = self._dependency_helper.GetInstallRequires(81 exclude_version=exclude_version, test_dependencies=True)82 return [83 test_dependency for test_dependency in test_dependencies84 if test_dependency not in python_dependencies]85 def _GetRPMPythonDependencies(self):86 """Retrieves RPM Python dependencies.87 Returns:88 list[str]: RPM package names of Python dependencies.89 """90 return self._dependency_helper.GetRPMRequires(exclude_version=True)91 def _GetRPMTestDependencies(self, python_dependencies):92 """Retrieves RPM test dependencies.93 Args:94 python_dependencies (list[str]): RPM package names of Python dependencies.95 Returns:96 list[str]: RPM package names of test dependencies.97 """98 test_dependencies = self._dependency_helper.GetRPMRequires(99 exclude_version=True, test_dependencies=True)100 # TODO: replace by test_dependencies.ini or dev_dependencies.ini or equiv.101 test_dependencies.extend(['python3-setuptools'])102 return [103 test_dependency for test_dependency in sorted(test_dependencies)104 if test_dependency not in python_dependencies]105 def _ReadTemplateFile(self, filename):106 """Reads a template string from file.107 Args:108 filename (str): name of the file containing the template string.109 Returns:110 string.Template: template string.111 """112 with io.open(filename, 'r', encoding='utf-8') as file_object:113 file_data = file_object.read()114 return string.Template(file_data)115 @abc.abstractmethod116 def Write(self):...

Full Screen

Full Screen

test_classes.py

Source:test_classes.py Github

copy

Full Screen

1from pathlib import Path2import shutil3from mayan.apps.common.tests.base import BaseTestCase4from mayan.apps.common.tests.utils import mute_stdout5from mayan.apps.storage.utils import mkdtemp6from .mocks import TestDependency7class DependencyClassTestCase(BaseTestCase):8 def setUp(self):9 super(DependencyClassTestCase, self).setUp()10 self.test_replace_text = 'replaced_text'11 self.temporary_directory = mkdtemp()12 self.path_temporary_directory = Path(self.temporary_directory)13 self.path_test_file = self.path_temporary_directory / 'test_file.css'14 with self.path_test_file.open(mode='w') as file_object:15 file_object.write(16 '@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic");'17 )18 self.test_dependency = TestDependency(19 name='test_dependency', module=__name__20 )21 def tearDown(self):22 super(DependencyClassTestCase, self).tearDown()23 shutil.rmtree(self.temporary_directory, ignore_errors=True)24 def _patch_test_file(self):25 replace_list = [26 {27 'filename_pattern': '*',28 'content_patterns': [29 {30 'search': '"https://fonts.googleapis.com/css?family=Lato:400,700,400italic"',31 'replace': self.test_replace_text,32 }33 ]34 }35 ]36 with mute_stdout():37 self.test_dependency.patch_files(38 path=self.temporary_directory, replace_list=replace_list39 )40 with self.path_test_file.open(mode='r') as file_object:41 self.final_text = file_object.read()42 def test_file_patching(self):43 self._patch_test_file()44 self.assertEqual(45 self.final_text, '@import url({});'.format(self.test_replace_text)...

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