-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve CollisionError string representations
- Loading branch information
Showing
4 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/python3 | ||
|
||
"""Tests for custom errors""" | ||
|
||
from unittest import TestCase | ||
from lambda_calculus import errors | ||
|
||
|
||
class CollisionErrorTest(TestCase): | ||
"""Tests for Exception thrown when a variable already exists""" | ||
|
||
def test_exception(self) -> None: | ||
"""test exception subclass""" | ||
exception: Exception = errors.CollisionError("test", []) | ||
self.assertIsInstance(exception, ValueError) | ||
self.assertEqual(exception.args, ("test", [])) | ||
|
||
def test_repr(self) -> None: | ||
"""test string representation""" | ||
exception: Exception = errors.CollisionError("test", []) | ||
self.assertEqual( | ||
repr(exception), | ||
f"lambda_calculus.errors.CollisionError({'test'!r}, {[]!r})" | ||
) | ||
|
||
def test_str(self) -> None: | ||
"""test exception message""" | ||
self.assertEqual( | ||
str(errors.CollisionError("test", [])), | ||
"[collisions: none] test" | ||
) | ||
self.assertEqual( | ||
str(errors.CollisionError("test", range(3))), | ||
"[collisions: 0, 1, 2] test" | ||
) |