Best Python code snippet using tox_python
conditions.py
Source:conditions.py
...6class DefaultCondition(BaseCondition):7 def check_typing(self, typing: Any) -> bool:8 return True9 def handle(self, typing: Any) -> Dict[str, Any]:10 for dependency in self._resolver.get_resolved_dependencies(typing):11 return dependency12 raise DependencyResolvingException(f"There is no such dependency in the container {typing}")13class AnyCondition(BaseCondition):14 _type_names_to_check = {"Any"}15 def check_typing(self, typing: Any) -> bool:16 if not check_generic_typing(typing, self._type_names_to_check):17 return False18 return True19 def handle(self, typing: Any) -> NoReturn:20 raise DependencyResolvingException(f"Any or empty annotation is not supported")21class UnionCondition(BaseCondition):22 def check_typing(self, typing: Any) -> bool:23 if not check_union_typing(typing):24 return False25 return True26 def handle(self, typing: Any) -> Optional[Dict[str, Any]]:27 args = typing.__args__28 if len(args) == 2 and args[1] is type(None):29 for dependency in self._resolver.get_resolved_dependencies(args[0]):30 return dependency31 return None32 for inner_type in args:33 for dependency in self._resolver.get_resolved_dependencies(inner_type):34 return dependency35 raise DependencyResolvingException(f"There is no such dependency in the container {typing}")36class CollectionCondition(BaseCondition):37 def check_typing(self, typing: Any) -> bool:38 if not check_collection_typing(typing):39 return False40 return True41 def handle(self, typing: Any) -> List[Dict[str, Any]]:42 field_attributes = []43 for inner_type in typing.__args__:44 for dependency in self._resolver.get_resolved_dependencies(inner_type):45 field_attributes.append(dependency)46 if not field_attributes:47 raise DependencyResolvingException(f"There is no such dependency in the container {typing}")48 return field_attributes49class IteratorCondition(BaseCondition):50 _type_names_to_check = {"Iterator"}51 def check_typing(self, typing: Any) -> bool:52 if not check_generic_typing(typing, self._type_names_to_check):53 return False54 return True55 def handle(self, typing: Any) -> Iterator[Any]:56 return self._iterator(typing.__args__)57 def _iterator(self, typings: Sequence[Any]):58 for typing in typings:59 for dependency in self._resolver.get_resolved_dependencies(typing):60 yield dependency61class ForwardRefCondition(BaseCondition):62 _type_names_to_check = {"ForwardRef"}63 def check_typing(self, typing: Any) -> bool:64 origin = getattr(typing, "__origin__", None)65 if origin is None:66 return False67 if issubclass(origin, ForwardRef):68 return True69 return False70 def handle(self, typing: Any) -> ForwardRef:71 forward_ref = typing(self._resolver, self._dependency_storage)72 typing_args = get_typing_args(typing)73 if not typing_args:74 raise Exception("It is necessary to transfer the generic to Forwardref")75 forward_ref._ForwardRef__set_generic_typing(typing_args[0])76 return forward_ref77class GenericCondition(BaseCondition):78 def check_typing(self, typing: Any) -> bool:79 if not get_typing_args(typing):80 return False81 return True82 def handle(self, typing: Any) -> Dict[str, Any]:83 for dependency in self._resolver.get_resolved_dependencies((typing, get_args(typing))):84 return dependency...
conftest.py
Source:conftest.py
...36 def _pcall(self, *args, **kwargs):37 return subprocess.Popen(*args, **kwargs)38 def _getresolvedeps(self):39 return self.deps40 def get_resolved_dependencies(self):41 # _getresolvedeps was deprecated on tox 3.7.0 in favor of get_resolved_dependencies42 return self.deps43class MockAction(object):44 def __init__(self, venv=None):45 self.venv = venv46 def setactivity(self, *args, **kwargs):47 pass48 def popen(self, *args, **kwargs):49 return subprocess.Popen(*args, **kwargs)50@pytest.fixture51def venv(tmpdir):52 venv = MockVenv(tmpdir)53 return venv54@pytest.fixture...
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!!