Skip to content

Commit a2a920b

Browse files
committed
fixes tests
1 parent c20155e commit a2a920b

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

sure/loader/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,16 @@ def __init__(self, path: Union[str, Path]):
263263
def is_module_dir(self) -> bool:
264264
return self.path.is_dir() and self.path.joinpath("__init__.py").is_file()
265265

266+
def is_module_file(self) -> bool:
267+
return self.path.is_file() and self.extension().endswith(".py")
268+
266269
def in_module_dir(self) -> bool:
267270
return (self.path.is_file() and self.path.name == "__init__.py") or (
268271
self.path.is_dir() and self.path.joinpath("__init__.py").is_file()
269272
)
270273

271274
def extension(self) -> bool:
272-
return os.path.splitext(str(self))[1]
273-
274-
def is_module_file(self) -> bool:
275-
return self.path.is_file() and self.path.extension().endswith(".py")
275+
return os.path.splitext(str(self.path))[1]
276276

277277
def is_module(self) -> bool:
278-
return self.path.is_module_dir() or self.path.is_module_file()
278+
return self.is_module_dir() or self.is_module_file()

sure/original.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ def raises(self, exc, msg=None):
147147
f'Expected to match regex: {repr(msg.pattern)}\n against:\n {repr(str(err))}'
148148
)
149149

150-
else:
151-
raise e
152150
else:
153151
if inspect.isbuiltin(self.actual):
154152
_src_filename = '<built-in function>'

tests/functional/loader/test_loader.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,21 @@ def test_module_path_in_module_dir_true_if_path_is_a_directory_and_parent_path_c
276276
assert module_path.in_module_dir() == True
277277

278278

279+
def test_module_path_is_module_file_true():
280+
"sure.loader.ModulePath.is_module_file returns `True' when pointing to a path referencing a `*.py' file"
281+
282+
module_path = ModulePath(Path(__file__))
283+
assert module_path.is_module_file() == True
284+
285+
286+
def test_module_path_is_module_file_false_if_path_is_not_a_file():
287+
"sure.loader.ModulePath.is_module_file returns `False' when pointing to a path not referencing a file"
288+
289+
path = Path(__file__).parent
290+
module_path = ModulePath(path)
291+
assert module_path.is_module_file() == False
292+
293+
279294
def test_module_path_in_module_dir_false_if_path_does_not_contain_init_file():
280295
"sure.loader.ModulePath.in_module_dir returns `False' when pointing to a path whose parent directory contains a __init__.py file"
281296

@@ -292,3 +307,32 @@ def test_module_path_in_module_dir_true_if_path_is_not_a_directory_and_parent_pa
292307

293308
module_path = ModulePath(sure.__file__)
294309
assert module_path.in_module_dir() == True
310+
311+
312+
def test_module_path_is_module_file_true():
313+
"sure.loader.ModulePath.is_module_file returns `True' when pointing to a path referencing a `*.py' file"
314+
315+
module_path = ModulePath(Path(__file__))
316+
assert module_path.is_module_file() == True
317+
318+
319+
def test_module_path_extension_returns_file_extension():
320+
"sure.loader.ModulePath.is_module_file returns `False' when pointing to a path not referencing a file"
321+
322+
module_path = ModulePath(__file__)
323+
assert ".py" in module_path.extension()
324+
325+
326+
327+
def test_module_path_is_module_true_when_pointing_to_path_containing_init_file():
328+
"sure.loader.ModulePath.is_module returns `True' when pointing to a path containing a __init__.py file"
329+
330+
module_path = ModulePath(Path(__file__).parent)
331+
assert module_path.is_module() == True
332+
333+
334+
def test_module_path_is_module_true_when_pointing_to_path_to_python_file():
335+
"sure.loader.ModulePath.is_module returns `True' when pointing to a path referencing a `*.py' file"
336+
337+
module_path = ModulePath(Path(__file__).parent)
338+
assert module_path.is_module() == True

tests/test_original_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,3 +1644,12 @@ def test_assertion_helper_raises_fails_when_the_expected_error_does_not_happen_b
16441644
expects(assertion_helper.raises).when.called_with("error").to.have.raised(
16451645
"at <built-in function>:\ncalling vars() with args [] and kws {} did not raise 'error'"
16461646
)
1647+
1648+
1649+
def test_assertion_helper_equals():
1650+
class Test:
1651+
_attribute = "test"
1652+
1653+
test = AssertionHelper(Test)
1654+
1655+
assert expects(test.the_attribute("_attribute").equals).when.called_with("unknown").raises(AssertionError)

tests/unit/reporters/test_feature_reporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def contrive_exception_info():
279279
call.reset("\n"),
280280
call.reset(" "),
281281
call.yellow(
282-
f'Failure: contrived failure\n File "{collapse_path(__file__)}", line 253, in contrive_exception_info\n ErrorStack()\n'
282+
f'Failure: contrived failure\n File "{collapse_path(__file__)}", line 253, in contrive_exception_info\n ErrorStack()\n ~~~~~~~~~~^^\n'
283283
),
284284
call.reset(" "),
285285
call.bold_blue("\n Scenario:"),

0 commit comments

Comments
 (0)