-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow testing other module names by changing one line (#168)
* Make testing another package name a one line change * Don't use pyproject.toml as test data * Add a comment
- Loading branch information
Showing
5 changed files
with
33 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
__all__ = ("tomllib",) | ||
|
||
# By changing this one line, we can run the tests against | ||
# a different module name. | ||
import tomli as tomllib |
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 |
---|---|---|
@@ -1,39 +1,39 @@ | ||
import unittest | ||
|
||
import tomli | ||
from . import tomllib | ||
|
||
|
||
class TestError(unittest.TestCase): | ||
def test_line_and_col(self): | ||
with self.assertRaises(tomli.TOMLDecodeError) as exc_info: | ||
tomli.loads("val=.") | ||
with self.assertRaises(tomllib.TOMLDecodeError) as exc_info: | ||
tomllib.loads("val=.") | ||
self.assertEqual(str(exc_info.exception), "Invalid value (at line 1, column 5)") | ||
|
||
with self.assertRaises(tomli.TOMLDecodeError) as exc_info: | ||
tomli.loads(".") | ||
with self.assertRaises(tomllib.TOMLDecodeError) as exc_info: | ||
tomllib.loads(".") | ||
self.assertEqual( | ||
str(exc_info.exception), "Invalid statement (at line 1, column 1)" | ||
) | ||
|
||
with self.assertRaises(tomli.TOMLDecodeError) as exc_info: | ||
tomli.loads("\n\nval=.") | ||
with self.assertRaises(tomllib.TOMLDecodeError) as exc_info: | ||
tomllib.loads("\n\nval=.") | ||
self.assertEqual(str(exc_info.exception), "Invalid value (at line 3, column 5)") | ||
|
||
with self.assertRaises(tomli.TOMLDecodeError) as exc_info: | ||
tomli.loads("\n\n.") | ||
with self.assertRaises(tomllib.TOMLDecodeError) as exc_info: | ||
tomllib.loads("\n\n.") | ||
self.assertEqual( | ||
str(exc_info.exception), "Invalid statement (at line 3, column 1)" | ||
) | ||
|
||
def test_missing_value(self): | ||
with self.assertRaises(tomli.TOMLDecodeError) as exc_info: | ||
tomli.loads("\n\nfwfw=") | ||
with self.assertRaises(tomllib.TOMLDecodeError) as exc_info: | ||
tomllib.loads("\n\nfwfw=") | ||
self.assertEqual(str(exc_info.exception), "Invalid value (at end of document)") | ||
|
||
def test_invalid_char_quotes(self): | ||
with self.assertRaises(tomli.TOMLDecodeError) as exc_info: | ||
tomli.loads("v = '\n'") | ||
with self.assertRaises(tomllib.TOMLDecodeError) as exc_info: | ||
tomllib.loads("v = '\n'") | ||
self.assertTrue(" '\\n' " in str(exc_info.exception)) | ||
|
||
def test_module_name(self): | ||
self.assertEqual(tomli.TOMLDecodeError().__module__, "tomli") | ||
self.assertEqual(tomllib.TOMLDecodeError().__module__, tomllib.__name__) |
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