Skip to content

Commit

Permalink
presents a more complex test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Sep 25, 2023
1 parent a080d5c commit a6528bb
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sure/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def seem_to_indicate_test(name: str) -> bool:
return re.search(r"^(Ensure|Test|Spec|Scenario)", name or "", re.I)


def seem_to_indicate_setup(name: str) -> bool:
return re.search(r"^(setUp|setup|set_up)$", name or "")


def seem_to_indicate_teardown(name: str) -> bool:
return re.search(r"^(tearDown|teardown|tear_down)$", name or "")


class Logort(object):
def __init__(self, scenario):
self.internal = logging.getLogger(__name__)
Expand Down Expand Up @@ -312,9 +320,14 @@ def __init__(self, class_or_callable, feature):
self.feature = feature
self.fail_immediately = False

def run_class_based_test(self, context) -> PreparedTestSuiteContainer:
def run_class_based_test(self, context):
# TODO: wrap logic in PreparedTestSuiteContainer
# XXX: def run_class_based_test(self, context) -> PreparedTestSuiteContainer:
last_failure = None
last_error = None
test_methods = []
setup_methods = []
teardown_methods = []
for name in dir(self.object):
if last_failure and context.runtime.immediate:
# XXX: raise last_failure
Expand Down
111 changes: 111 additions & 0 deletions tests/runner/test_zwei.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*-
from sure import that
from unittest import TestCase

feature = "nested tests"


class TestMoor(TestCase):
"`sure' should recognize nested test classes"

class TestEggcelent(TestCase):
"First Nested Test"

def test_101(self):
assert that("one").should.equal("one")

def test_201(self):
assert that("two").should_not.equal("one")

class TestAnother(TestCase):
"Another Nested Test"

def test_301(self):
assert that("three").should_not.equal("one")


class TestContextualized(TestCase):
"Another Nested Test"

def setup(self):
self.datum = {}

def test_empty_context(self):
assert that(self.datum).should.be.empty

def test_non_ideal_side_effect_0(self):
self.datum['side-effects'] = 0
assert that(self.datum).should.equal({
'side-effects': 0,
})

def test_non_ideal_side_effect_1(self):
assert that(self.datum).should.equal({
'side-effects': 0,
})
self.datum['extra-side-effects'] = {}
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {},
})

def test_non_ideal_side_effect_2(self):
assert that(self.datum).should.equal({
'side-effects': 0,
})
self.datum['extra-side-effects']['placate-code'] = (
'tests ideally should not cause side-effects'
)
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {
'placate-code': 'tests ideally should not cause side-effects'
},
})

def test_non_ideal_side_effect_3(self):
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {
'placate-code': 'tests ideally should not cause side-effects'
},
})
self.datum['extra-side-effects']['acknowledge-exception'] = (
"for broad adoption `sure' should support running tests in deterministic, alphabetic order so that existing codebases that rely on side-effects will continue to work as expected"
)
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {
'placate-code': 'tests ideally should not cause side-effects',
'acknowledge-exception': "for broad adoption `sure' should support running tests in deterministic, alphabetic order so that existing codebases that rely on side-effects will continue to work as expected"
},
})

def test_non_ideal_side_effect_4(self):
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {
'placate-code': 'tests ideally should not cause side-effects',
'acknowledge-exception': "for broad adoption `sure' should support running tests in deterministic, alphabetic order so that existing codebases that rely on side-effects will continue to work as expected"
},
})
self.datum['session-1'] = []
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {
'placate-code': 'tests ideally should not cause side-effects',
'acknowledge-exception': "for broad adoption `sure' should support running tests in deterministic, alphabetic order so that existing codebases that rely on side-effects will continue to work as expected"
},
'session-1': [],
})

def test_non_ideal_side_effect_5(self):
assert that(self.datum).should.equal({
'side-effects': 0,
'extra-side-effects': {
'placate-code': 'tests ideally should not cause side-effects',
'acknowledge-exception': "for broad adoption `sure' should support running tests in deterministic, alphabetic order so that existing codebases that rely on side-effects will continue to work as expected"
},
'session-1': [],
})
self.datum['session-1'].append("The somewhat complex rationale presented in this instance to be quite reasonable thus far")

0 comments on commit a6528bb

Please sign in to comment.