Best Python code snippet using green
reporting.py
Source: reporting.py
...57 if isinstance(golden, float):58 if not isinstance(value, float):59 return self._record_mismatch_type_failure('float', value)60 if abs(value - golden) / golden > 1e-4:61 return self._record_failure(62 f'value ({value!r}) is not close to golden value ({golden!r})'63 )64 return65 if isinstance(golden, int):66 if not isinstance(value, int):67 return self._record_mismatch_type_failure('int', value)68 if value != golden:69 return self._record_failure(70 f'value ({value!r}) is not equal to golden value ({golden!r})'71 )72 return73 if isinstance(golden, str):74 if not isinstance(value, str):75 return self._record_mismatch_type_failure('str', value)76 if value != golden:77 return self._record_failure(78 f'value ({value!r}) is not equal to golden value ({golden!r})'79 )80 return81 if isinstance(golden, tuple):82 if not isinstance(value, tuple):83 return self._record_mismatch_type_failure('tuple', value)84 if len(value) != len(golden):85 return self._record_failure(86 f'value ({len(value)!r}) is not equal to golden value ({len(golden)!r})'87 )88 reports = [89 ValueReport(v, g, self.context.chain(f'tuple element {i}'))90 for i, (v, g) in enumerate(zip(value, golden))91 ]92 for report in reports:93 if report.failed:94 self.failure_reasons.extend(report.failure_reasons)95 return96 if isinstance(golden, list):97 if not isinstance(value, list):98 return self._record_mismatch_type_failure('list', value)99 if len(value) != len(golden):100 return self._record_failure(101 f'value ({len(value)!r}) is not equal to golden value ({len(golden)!r})'102 )103 reports = [104 ValueReport(v, g, self.context.chain(f'list element {i}'))105 for i, (v, g) in enumerate(zip(value, golden))106 ]107 for report in reports:108 if report.failed:109 self.failure_reasons.extend(report.failure_reasons)110 return111 if isinstance(golden, dict):112 if not isinstance(value, dict):113 return self._record_mismatch_type_failure('dict', value)114 gkeys = list(sorted(golden.keys()))115 vkeys = list(sorted(value.keys()))116 if gkeys != vkeys:117 return self._record_failure(118 f'dict keys ({vkeys!r}) are not equal to golden keys ({gkeys!r})'119 )120 reports = [121 ValueReport(value[k], golden[k],122 self.context.chain(f'dict element at key {k!r}'))123 for k in gkeys124 ]125 for report in reports:126 if report.failed:127 self.failure_reasons.extend(report.failure_reasons)128 return129 if isinstance(golden, torch.Tensor):130 if not isinstance(value, torch.Tensor):131 return self._record_mismatch_type_failure('torch.Tensor', value)132 if value.shape != golden.shape:133 return self._record_failure(134 f'shape ({value.shape}) is not equal to golden shape ({golden.shape})'135 )136 if value.dtype != golden.dtype:137 return self._record_failure(138 f'dtype ({value.dtype}) is not equal to golden dtype ({golden.dtype})'139 )140 if not torch.allclose(value, golden, rtol=1e-03, atol=1e-07, equal_nan=True):141 return self._record_failure(142 f'value ({TensorSummary(value)}) is not close to golden value ({TensorSummary(golden)})'143 )144 return145 return self._record_failure(146 f'unexpected golden value of type `{golden.__class__.__name__}`')147 def _record_failure(self, s: str):148 self.failure_reasons.append(self.context.format_error(s))149 def _record_mismatch_type_failure(self, expected: str, actual: Any):150 self._record_failure(151 f'expected a value of type `{expected}` but got `{actual.__class__.__name__}`'152 )153class TraceItemReport:154 """A report for a single trace item."""155 failure_reasons: List[str]156 def __init__(self, item: TraceItem, golden_item: TraceItem,157 context: ErrorContext):158 self.item = item159 self.golden_item = golden_item160 self.context = context161 self.failure_reasons = []162 self._evaluate_outcome()163 @property164 def failed(self):...
telemetry.py
Source: telemetry.py
...51 def update_telemetry(self, auth_result):52 if auth_result:53 with self._lock:54 if "error" in auth_result:55 self._record_failure(auth_result["error"])56 else: # Telemetry sent successfully. Reset buffer57 self._buffer.clear() # This won't work: self._buffer = {}58 def _record_failure(self, error):59 simulation = len(",{api_id},{correlation_id},{error}".format(60 api_id=self._api_id, correlation_id=self._correlation_id, error=error))61 if self._buffer.get(self._FAILURE_SIZE, 0) + simulation < self._LAST_HEADER_SIZE_LIMIT:62 self._buffer[self._FAILURE_SIZE] = self._buffer.get(63 self._FAILURE_SIZE, 0) + simulation64 self._buffer.setdefault(self._FAILED, []).append({...
Check out the latest blogs from LambdaTest on this topic:
It is essential for a team, when speaking about test automation, to take the time needed to think, analyze and try what will be the best tool, framework, and language that suits your team’s needs.
In this digital era, Continuous Integration and Continuous Deployment is closely aligned with software development and agile methodologies. Organizations deploy latest versions of software products every minute to ensure maximum competitive edge.
Test Coverage and Code coverage are the most popular methodologies for measuring the effectiveness of the code. Though these terms are sometimes used interchangeably since their underlying principles are the same. But they are not as similar as you may think. Many times, I have noticed the testing team and development team being confused over the use of these two terminologies. Which is why I thought of coming up with an article to talk about the differences between code coverage and test coverage in detail.
When someone develops a website, going live it’s like a dream come true. I have also seen one of my friends so excited as he was just about to launch his website. When he finally hit the green button, some unusual trend came suddenly into his notice. After going into details, he found out that the website has a very high bounce rate on Mobile devices. Thanks to Google Analytics, he was able to figure that out.
With an average global salary of $39k, PHP is one of the most popular programming languages in the developer community. It’s the language behind the most popular CMS, WordPress. It is in-use by 79% of total websites globally, including the most used social network- Facebook, the largest digital encyclopedia – Wikipedia, China’s news giant Xinhuanet, and Russia’s social network VK.com.
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!!