How to use _validate_real method in assertpy

Best Python code snippet using assertpy_python

assertions.py

Source:assertions.py Github

copy

Full Screen

...334 def _validate_number(self):335 """Raise TypeError if val is not numeric."""336 if isinstance(self.val, numbers.Number) is False:337 raise TypeError('val is not numeric')338 def _validate_real(self):339 """Raise TypeError if val is not real number."""340 if isinstance(self.val, numbers.Real) is False:341 raise TypeError('val is not real number')342 def is_zero(self):343 """Asserts that val is numeric and equal to zero."""344 self._validate_number()345 return self.is_equal_to(0)346 def is_not_zero(self):347 """Asserts that val is numeric and not equal to zero."""348 self._validate_number()349 return self.is_not_equal_to(0)350 def is_nan(self):351 """Asserts that val is real number and NaN (not a number)."""352 self._validate_number()353 self._validate_real()354 if not math.isnan(self.val):355 self._err('Expected <%s> to be <NaN>, but was not.' % self.val)356 return self357 def is_not_nan(self):358 """Asserts that val is real number and not NaN (not a number)."""359 self._validate_number()360 self._validate_real()361 if math.isnan(self.val):362 self._err('Expected not <NaN>, but was.')363 return self364 def is_inf(self):365 """Asserts that val is real number and Inf (infinity)."""366 self._validate_number()367 self._validate_real()368 if not math.isinf(self.val):369 self._err('Expected <%s> to be <Inf>, but was not.' % self.val)370 return self371 def is_not_inf(self):372 """Asserts that val is real number and not Inf (infinity)."""373 self._validate_number()374 self._validate_real()375 if math.isinf(self.val):376 self._err('Expected not <Inf>, but was.')377 return self378 def is_greater_than(self, other):379 """Asserts that val is numeric and is greater than other."""380 self._validate_compareable(other)381 if self.val <= other:382 if type(self.val) is datetime.datetime:383 self._err('Expected <%s> to be greater than <%s>, but was not.' % (384 self.val.strftime('%Y-%m-%d %H:%M:%S'), other.strftime('%Y-%m-%d %H:%M:%S')))385 else:386 self._err('Expected <%s> to be greater than <%s>, but was not.' % (self.val, other))387 return self388 def is_greater_than_or_equal_to(self, other):...

Full Screen

Full Screen

numeric.py

Source:numeric.py Github

copy

Full Screen

...52 def _validate_number(self):53 """Raise TypeError if val is not numeric."""54 if isinstance(self.val, numbers.Number) is False:55 raise TypeError('val is not numeric')56 def _validate_real(self):57 """Raise TypeError if val is not real number."""58 if isinstance(self.val, numbers.Real) is False:59 raise TypeError('val is not real number')60 def is_zero(self):61 """Asserts that val is numeric and is zero.62 Examples:63 Usage::64 assert_that(0).is_zero()65 Returns:66 AssertionBuilder: returns this instance to chain to the next assertion67 Raises:68 AssertionError: if val is **not** zero69 """70 self._validate_number()71 return self.is_equal_to(0)72 def is_not_zero(self):73 """Asserts that val is numeric and is *not* zero.74 Examples:75 Usage::76 assert_that(1).is_not_zero()77 assert_that(123.4).is_not_zero()78 Returns:79 AssertionBuilder: returns this instance to chain to the next assertion80 Raises:81 AssertionError: if val **is** zero82 """83 self._validate_number()84 return self.is_not_equal_to(0)85 def is_nan(self):86 """Asserts that val is real number and is ``NaN`` (not a number).87 Examples:88 Usage::89 assert_that(float('nan')).is_nan()90 assert_that(float('inf') * 0).is_nan()91 Returns:92 AssertionBuilder: returns this instance to chain to the next assertion93 Raises:94 AssertionError: if val is **not** NaN95 """96 self._validate_number()97 self._validate_real()98 if not math.isnan(self.val):99 return self.error('Expected <%s> to be <NaN>, but was not.' % self.val)100 return self101 def is_not_nan(self):102 """Asserts that val is real number and is *not* ``NaN`` (not a number).103 Examples:104 Usage::105 assert_that(0).is_not_nan()106 assert_that(123.4).is_not_nan()107 assert_that(float('inf')).is_not_nan()108 Returns:109 AssertionBuilder: returns this instance to chain to the next assertion110 Raises:111 AssertionError: if val **is** NaN112 """113 self._validate_number()114 self._validate_real()115 if math.isnan(self.val):116 return self.error('Expected not <NaN>, but was.')117 return self118 def is_inf(self):119 """Asserts that val is real number and is ``Inf`` (infinity).120 Examples:121 Usage::122 assert_that(float('inf')).is_inf()123 assert_that(float('inf') * 1).is_inf()124 Returns:125 AssertionBuilder: returns this instance to chain to the next assertion126 Raises:127 AssertionError: if val is **not** Inf128 """129 self._validate_number()130 self._validate_real()131 if not math.isinf(self.val):132 return self.error('Expected <%s> to be <Inf>, but was not.' % self.val)133 return self134 def is_not_inf(self):135 """Asserts that val is real number and is *not* ``Inf`` (infinity).136 Examples:137 Usage::138 assert_that(0).is_not_inf()139 assert_that(123.4).is_not_inf()140 assert_that(float('nan')).is_not_inf()141 Returns:142 AssertionBuilder: returns this instance to chain to the next assertion143 Raises:144 AssertionError: if val **is** Inf145 """146 self._validate_number()147 self._validate_real()148 if math.isinf(self.val):149 return self.error('Expected not <Inf>, but was.')150 return self151 def is_greater_than(self, other):152 """Asserts that val is numeric and is greater than other.153 Args:154 other: the other date, expected to be less than val155 Examples:156 Usage::157 assert_that(1).is_greater_than(0)158 assert_that(123.4).is_greater_than(111.1)159 For dates, behavior is identical to :meth:`~assertpy.date.DateMixin.is_after`::160 import datetime161 today = datetime.datetime.now()...

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