Best Python code snippet using molotov_python
__init__.py
Source:__init__.py
1"""2âââââââââââââââââââ3â Main interfaces â4âââââââââââââââââââ5 Florian Dupeyron6 July 20227"""8from dataclasses import dataclass, field9from typing import Optional, Dict10# ââââââââââââââââââââââââââââââââââââââââââ11# â BaseValue base class â12# ââââââââââââââââââââââââââââââââââââââââââ13@dataclass(kw_only=True)14class BaseValue:15 class_id: str = ""16 def __post_init__(self):17 pass18 # âââââââââââ Fixture property âââââââââââ #19 # This property can be reimplemented by subclasses20 # For specific behaviour, for example when a interface21 # Groups specific interfaces.22 @property23 def fixture(self):24 return None25 26 @fixture.setter27 def fixture(self, fixt):28 pass29# ââââââââââââââââââââââââââââââââââââââââââ30# â AtomicValue interface class â31# ââââââââââââââââââââââââââââââââââââââââââ32@dataclass(kw_only=True)33class AtomicValue(BaseValue):34 def __post_init__(self):35 super().__post_init__()36 self.__fixture = None37 @property38 def fixture(self):39 return self.__fixture40 41 @fixture.setter42 def fixture(self, fixt):43 self.__fixture = fixt44# ââââââââââââââââââââââââââââââââââââââââââ45# â GroupValue interface class â46# ââââââââââââââââââââââââââââââââââââââââââ47@dataclass(kw_only=True)48class GroupValue(BaseValue):49 def __post_init__(self):50 super().__post_init__()51 self.__fixture = None52 @property53 def fixture(self):54 return self.__fixture55 56 57 @fixture.setter58 def fixture(self, fixt):59 self.__fixture = fixt60 # Attach to children61 for ch_name, ch in self.__dict__.items():62 if isinstance(ch, BaseValue):63 ch.fixture = self.__fixture64# ââââââââââââââââââââââââââââââââââââââââââ65# â RangeValue interface class â66# ââââââââââââââââââââââââââââââââââââââââââ67@dataclass(kw_only=True)68class RangeValue(AtomicValue):69 min: float70 max: float71 72 unit: Optional[str] = ""73 class_id: str = "RangeValue"74 # âââââââââââââââ Post init ââââââââââââââ #75 76 def __post_init__(self):77 super().__post_init__()78 self._value = 079 # ââââââââââââââ Set and get âââââââââââââ #80 81 def set(self, v):82 if v < self.min: raise ValueError(f"{v} < {self.min}")83 elif v > self.max: raise ValueError(f"{v} > {self.max}")84 else:85 self._value = v86 self._on_set(v)87 def get(self):88 return self._value89 # âââââââââââââââââ Hooks ââââââââââââââââ #90 91 def _on_set(self, v):92 pass93# ââââââââââââââââââââââââââââââââââââââââââ94# â DiscreteValue interface class â95# ââââââââââââââââââââââââââââââââââââââââââ96@dataclass(kw_only=True)97class DiscreteValue_Choice:98 label: str99 value: any100 image: Optional[str] = ""101@dataclass(kw_only=True)102class DiscreteValue(AtomicValue):103 choices: Dict[str, DiscreteValue_Choice]104 class_id: str = "DiscreteValue"105 # âââââââââââââââ Post init ââââââââââââââ #106 107 def __post_init__(self):108 super().__post_init__()109 self._value = None110 # âââââââââââââââ Set / Get ââââââââââââââ #111 112 def set(self, v):113 if not v in self.choices: raise ValueError(f"Invalid discrete value {v}")114 else:115 self._value = v116 self._on_set(v)117 def get(self):118 return self._value119 # ââââââââ Hooks to be implemented âââââââ #120 def _on_set(self, v):121 pass122# ââââââââââââââââââââââââââââââââââââââââââ123# â ColorValue interface â124# ââââââââââââââââââââââââââââââââââââââââââ125@dataclass(kw_only=True)126class ColorValue(GroupValue):127 r: RangeValue128 g: RangeValue129 b: RangeValue130 class_id: str = "ColorValue"131# ââââââââââââââââââââââââââââââââââââââââââ132# â RotationValue interface â133# ââââââââââââââââââââââââââââââââââââââââââ134@dataclass(kw_only=True)135class RotationValue(GroupValue):136 pan: RangeValue137 tilt: RangeValue138 ...
test_github_event_handler.py
Source:test_github_event_handler.py
...50 'actions': ['unlabeled']51 },52 ]53 }54 def __fixture(self, example_file_name):55 return open(os.path.dirname(os.path.realpath(__file__)) + '/../examples/' + example_file_name)56 def test_pull_request(self):57 jenkins_mock = mock.MagicMock()58 handler = GithubEventHandler(Config(self.config), jenkins_mock)59 with self.__fixture('pull_request.json') as fp:60 payload = json.load(fp)61 handler.process_github_event('pull_request', payload)62 expected_params = {63 'repo': 'Wikia/sparrow',64 'branch': 'test-branch',65 'commit': 'f96bc53e42b40dbbd0ceb19b68a3365e7a66f223',66 'pull_num': 31,67 'labels': []68 }69 jenkins_mock.build_job.assert_called_once_with('job5', expected_params)70 def test_pull_request_review_comment(self):71 jenkins_mock = mock.MagicMock()72 handler = GithubEventHandler(Config(self.config), jenkins_mock)73 with self.__fixture('pull_request_review_comment.json') as fp:74 payload = json.load(fp)75 handler.process_github_event('pull_request_review_comment', payload)76 expected_params = {77 'repo': 'Wikia/sparrow',78 'branch': 'test-branch',79 'commit': 'f96bc53e42b40dbbd0ceb19b68a3365e7a66f223',80 'pull_num': 31,81 }82 jenkins_mock.build_job.assert_called_once_with('job5', expected_params)83 def test_push(self):84 jenkins_mock = mock.MagicMock()85 handler = GithubEventHandler(Config(self.config), jenkins_mock)86 with self.__fixture('push.json') as fp:87 payload = json.load(fp)88 handler.process_github_event('push', payload)89 expected_params = {90 'repo': 'Wikia/app',91 'author': 'Kyle Daigle',92 'branch': 'wikia-logger-backtrace-for-errors',93 'commit': '4d2ab4e76d0d405d17d1a0f2b8a6071394e3ab40',94 'email': 'kyle.daigle@github.com'95 }96 jenkins_mock.build_job.assert_called_once_with('job3', expected_params)97 def test_extra_job_params(self):98 jenkins_mock = mock.MagicMock()99 handler = GithubEventHandler(Config(self.config), jenkins_mock)100 with self.__fixture('pull_request_other_repo.json') as fp:101 payload = json.load(fp)102 handler.process_github_event('pull_request', payload)103 expected_params = {104 'repo': 'Wikia/other',105 'branch': 'test-branch',106 'commit': 'f96bc53e42b40dbbd0ceb19b68a3365e7a66f223',107 'pull_num': 31,108 'silent': 'true',109 'labels': []110 }111 jenkins_mock.build_job.assert_called_once_with('job4', expected_params)112 def test_pull_request_with_action(self):113 jenkins_mock = mock.MagicMock()114 handler = GithubEventHandler(Config(self.config), jenkins_mock)115 with self.__fixture('pull_request_with_action.json') as fp:116 payload = json.load(fp)117 handler.process_github_event('pull_request', payload)118 expected_params = {119 'repo': 'Wikia/ad-engine',120 'branch': 'ADEN-6924',121 'commit': 'e8f4b7c5a2c40fe14513ce27cc013cd7f779f9cc',122 'pull_num': 122,123 'labels': 'Any Label'124 }125 jenkins_mock.build_job.assert_called_once_with('aden-action-job', expected_params)126 def test_pull_request_merged_labels(self):127 jenkins_mock = mock.MagicMock()128 handler = GithubEventHandler(Config(self.config), jenkins_mock)129 with self.__fixture('pull_request_merged.json') as fp:130 payload = json.load(fp)131 handler.process_github_event('pull_request', payload)132 expected_params = {133 'repo': 'Wikia/ad-engine',134 'branch': 'ADEN-6924',135 'commit': 'e8f4b7c5a2c40fe14513ce27cc013cd7f779f9cc',136 'pull_num': 120,137 'labels': 'Major change,Foo'138 }...
test_PrometheusCounters.py
Source:test_PrometheusCounters.py
1# -*- coding: utf-8 -*-2import os3from pip_services3_commons.config import ConfigParams4from pip_services3_prometheus.count.PrometheusCounters import PrometheusCounters5from test.fixtures.CountersFixture import CountersFixture6class TestPrometheusCounters:7 __counters = None8 __fixture = None9 def setup_method(self, method=None):10 host = os.environ.get('PUSHGATEWAY_SERVICE_HOST') or 'localhost'11 port = os.environ.get('PUSHGATEWAY_SERVICE_PORT') or 909112 self.__counters = PrometheusCounters()13 self.__fixture = CountersFixture(self.__counters)14 config = ConfigParams.from_tuples(15 'source', 'test',16 'connection.host', host,17 'connection.port', port18 )19 self.__counters.configure(config)20 self.__counters.open(None)21 def teardown_method(self, method=None):22 self.__counters.close(None)23 def test_simple_counters(self):24 self.__fixture.test_simple_counters()25 def test_measure_elapsed_time(self):...
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!!