Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Dec 4, 2023
1 parent 9bc9004 commit 8e1ae1d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ test tests: clean | $(VENV)/bin/pytest # $(VENV)/bin/nosetests # @$(VENV)/bin/no

# run main command-line tool
run: | $(MAIN_CLI_PATH)
$(MAIN_CLI_PATH) --immediate tests/runner/test_eins.py
$(MAIN_CLI_PATH) --immediate tests/runner/
$(MAIN_CLI_PATH) --immediate tests/
$(MAIN_CLI_PATH) tests/runner/test_eins.py
$(MAIN_CLI_PATH) tests/runner/
$(MAIN_CLI_PATH) tests/
$(MAIN_CLI_PATH) --immediate

# Pushes release of this package to pypi
Expand Down
10 changes: 6 additions & 4 deletions sure/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sys
from functools import reduce


Expand All @@ -41,23 +42,24 @@ def __init__(self, scenario_result):
class ImmediateError(RuntimeInterruption):
def __init__(self, scenario_result):
self.args = scenario_result.error.args
super().__init__(scenario_result)
self.message = "".join(self.args)
super().__init__(scenario_result)


class ImmediateFailure(RuntimeInterruption):
def __init__(self, scenario_result):
super().__init__(scenario_result)
self.args = scenario_result.failure.args
self.message = self.result.succinct_failure
super().__init__(scenario_result)


class ExitError(SystemExit):
def __init__(self, context, result):
context.reporter.on_failure(result.scenario, result.error)
context.reporter.on_failure(result.scenario, result.succinct_error)
return super().__init__(exit_code('ERROR'))


class ExitFailure(SystemExit):
def __init__(self, context, result):
context.reporter.on_failure(result.scenario, result)
context.reporter.on_failure(result.scenario, result.succinct_failure)
return super().__init__(exit_code('FAILURE'))
19 changes: 14 additions & 5 deletions sure/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Logort(object):
def __init__(self, scenario):
self.internal = logging.getLogger(".".join((__name__, object_name(scenario))))
self.internal.handlers = []
self.internal.addHandler(logging.FileHandler(f"/tmp/sure%{os.getpid()}.log"))
self.internal.addHandler(self.log_handler())
scenario_id = getattr(scenario, "id", None)
scenario_id = callable(scenario_id) and scenario_id() or scenario_id
self.external = logging.getLogger(scenario_id)
Expand All @@ -167,13 +167,21 @@ def __init__(self, scenario):
self.external,
]

@classmethod
def log_handler(cls):
return logging.FileHandler(f"/tmp/sure%{os.getpid()}.log")

@property
def current(self):
return self.history[-1]

def set_location(self, location):
default_logger = logging.getLogger()
self.locations.append(location)
self.history.append(logging.getLogger(location.ort))
for logger in self.history:
logger.setLevel(default_logger.level)
logger.handlers = [self.log_handler]


class RuntimeOptions(object):
Expand Down Expand Up @@ -248,8 +256,8 @@ def __init__(
test_methods: List[Callable],
nested_suites: List[PreparedTestSuiteContainer],
):
self.log = Logort(source())
self.source_instance = source
self.source_instance = source()
self.log = Logort(self.source_instance)
self.context = context
self.setup_methods = setup_methods
self.teardown_methods = teardown_methods
Expand Down Expand Up @@ -283,7 +291,7 @@ def from_generic_object(cls, some_object, context: RuntimeContext):
if isinstance(some_object, type) and issubclass(
some_object, unittest.TestCase
):
# XXX: warn about probability of abuse of TestCase constructor taking non-standard arguments
# XXX: warn about probability of abuse of TestCase constructor taking wrong arguments
runnable = getattr(some_object(name), name, None)
else:
# XXX: support non-unittest.TestCase classes
Expand Down Expand Up @@ -329,6 +337,7 @@ def invoke_contextualized(self, runnable, context, name, location):
code = runnable.__code__
varnames = set(code.co_varnames).intersection({"context"})
argcount = len(varnames)

if argcount == 0:
runnable()
elif argcount == 1:
Expand Down Expand Up @@ -381,6 +390,7 @@ def run(self, context):
yield self.run_complements(context), RuntimeRole.Teardown

def run_container(self, container, context):
# concentrated area of test execution
return self.perform_unit(
test=container.unit,
context=context,
Expand Down Expand Up @@ -566,7 +576,6 @@ def __str__(self):

def printable(self):
prelude = f"{self.location}"

hook = ""
if callable(getattr(self.error, "printable", None)):
hook = self.error.printable()
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/test_eins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_function_ok():

def test_function_fail():
"testing failing function with sure runner"
assert False, 'the failure appears to be right'
assert False, "this very message SHALL aid in tracing back to the error's root-cause"


class TestClass(TestCase):
Expand Down

0 comments on commit 8e1ae1d

Please sign in to comment.