Skip to content

Commit

Permalink
presents more test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Jan 20, 2024
1 parent 4b8743a commit c7742af
Show file tree
Hide file tree
Showing 17 changed files with 637 additions and 198 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -55,6 +55,7 @@ docs: html-docs
$(OPEN_COMMAND) docs/build/html/index.html

test tests:
@$(VENV)/bin/pytest --cov=sure tests/test_runtime/test_scenario_result.py
@$(VENV)/bin/pytest --cov=sure tests

# runs main command-line tool
Expand Down
16 changes: 8 additions & 8 deletions sure/__init__.py
Expand Up @@ -753,7 +753,7 @@ def contains(self, expectation):
if expectation in self.actual:
return True
else:
raise Explanation(f'{expectation} should be in {self.actual}').as_assertion(self.actual, expectation, "Content Verification Error")
raise Explanation(f"`{expectation}' should be in `{self.actual}'").as_assertion(self.actual, expectation, "Content Verification Error")

contain = contains
to_contain = contains
Expand All @@ -763,7 +763,7 @@ def does_not_contain(self, expectation):
if expectation not in self.actual:
return True
else:
raise Explanation(f'{expectation} should not be in {self.actual}').as_assertion(self.actual, expectation, "Content Verification Error")
raise Explanation(f"`{expectation}' should not be in `{self.actual}'").as_assertion(self.actual, expectation, "Content Verification Error")

doesnt_contain = does_not_contain
to_not_contain = does_not_contain
Expand Down Expand Up @@ -805,22 +805,22 @@ def within(self, first, *rest):
# instead of hardcoding ``.should_not.be.within`` and ``.should.be.within`` in the
# variable assignments below
if self.negative:
ppath = "{0}.should_not.be.within".format(self.actual)
ppath = f"({self.actual}).should_not.be.within"
else:
ppath = "{0}.should.be.within".format(self.actual)
ppath = f"({self.actual}).should.be.within".format(self.actual)

raise AssertionError(
(
"{0}({1}, {2}) must be called with either a iterable:\n"
"{0}({1}, {2}) must be called with either an iterable:\n"
"{0}([1, 2, 3, 4])\n"
"or with a range of numbers:"
"{0}(1, 3000)"
"or with a range of numbers, i.e.: "
"`{0}(1, 3000)'"
).format(ppath, first, ", ".join([repr(x) for x in rest]))
)

@assertionmethod
def equal(self, expectation, epsilon=None):
"""compares given object ``X'` with an expected '`Y'` object.
"""compares given object ``X'` with an expected '`Y'` object.
It primarily assures that the compared objects are absolute equal '`=='`.
Expand Down
3 changes: 2 additions & 1 deletion sure/core.py
Expand Up @@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import types
from pprint import pformat
from typing import Union, List, Dict, Tuple
from collections import OrderedDict
from functools import cache
Expand All @@ -30,7 +31,7 @@

class Explanation(str):
def get_header(self, X, Y, suffix):
header = f"X = {repr(X)}\n and\nY = {repr(Y)}\n{str(suffix)}"
header = f"X = {pformat(X, sort_dicts=False, compact=False)}\n and\nY = {pformat(Y, sort_dicts=False, compact=False)}\n{str(suffix)}"
return yellow(header).strip()

def get_assertion(self, X, Y, prefix=""):
Expand Down
2 changes: 1 addition & 1 deletion sure/doubles/dummies.py
Expand Up @@ -77,7 +77,7 @@ def __eq__(self, given: object):
given_type = type(given)
module_name = given_type.__module__
type_name = given_type.__name__
return isinstance(given, self.__expected_type__) and super().__eq__(f"typed:{module_name}.{type_name}")
return isinstance(given, (self.__expected_type__, self.__class__)) and super().__eq__(f"typed:{module_name}.{type_name}")

def __repr__(self):
return f'<AnythingOfType[{self.__type_fqdn__}] {self.__dummy_id__}>'
Expand Down
5 changes: 3 additions & 2 deletions sure/errors.py
Expand Up @@ -112,8 +112,9 @@ def __init__(self, scenario_result: ScenarioResult):


class ExitError(ImmediateExit):
def __init__(self, context: RuntimeContext, result: ScenarioResult):
context.reporter.on_error(context, result)
def __init__(self, context: RuntimeContext, result: ScenarioResult, report:bool = True):
if report:
context.reporter.on_error(context, result)
return super().__init__(exit_code("ERROR"))


Expand Down
2 changes: 1 addition & 1 deletion sure/original.py
Expand Up @@ -134,7 +134,7 @@ def match(self, *args, **kw):

def raises(self, exc, msg=None):
if not callable(self.actual):
raise TypeError('%r is not callable' % self.actual)
raise TypeError(f'{self.actual} is not callable')

try:
self.actual(*self._callable_args, **self._callable_kw)
Expand Down

0 comments on commit c7742af

Please sign in to comment.