Closed nedbat closed 3 years ago
Like this:
=============================================================================== test session starts =============================================================================== platform darwin -- Python 3.6.10, pytest-6.1.0, py-1.9.0, pluggy-0.13.1 cachedir: .tox/py36/.pytest_cache rootdir: /Users/ned/scriv, configfile: setup.cfg plugins: mock-3.3.1 collected 86 items tests/test_collect.py ............. [ 15%] tests/test_config.py ..........F........... [ 40%] tests/test_create.py .................. [ 61%] tests/test_format_md.py ......... [ 72%] tests/test_format_rst.py ............ [ 86%] tests/test_gitinfo.py ..... [ 91%] tests/test_literals.py FFFF.. [ 98%] tests/test_process.py . [100%] ==================================================================================== FAILURES ===================================================================================== ______________________________________________________________________________ test_literal_reading _______________________________________________________________________________ temp_dir = PosixPath('/private/var/folders/j2/gr3cj3jn63s5q8g3bjvw57hm0000gp/T/pytest-of-ned/pytest-7/test_literal_reading0') def test_literal_reading(temp_dir): # Any setting can be read from a literal in a file. (temp_dir / "sub").mkdir() (temp_dir / "sub" / "foob.py").write_text( """# comment\n__version__ = "12.34.56"\n""" ) > text = Config(version="literal:sub/foob.py: __version__").version /Users/ned/scriv/tests/test_config.py:175: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <attrs generated init scriv.config.Config>:17: in __init__ self.__attrs_post_init__() /Users/ned/scriv/.tox/py36/lib/python3.6/site-packages/scriv/config.py:177: in __attrs_post_init__ self.resolve_all() /Users/ned/scriv/.tox/py36/lib/python3.6/site-packages/scriv/config.py:191: in resolve_all value = self.resolve_value(value) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = Config(fragment_directory='changelog.d', format='rst', categories=['Removed', 'Added', 'Changed', 'Deprecated', 'Fixed...date.strftime('%Y-%m-%d') }}", version='literal:sub/foob.py: __version__', main_branches=['master', 'main', 'develop']) value = 'literal:sub/foob.py: __version__' def resolve_value(self, value: str) -> str: """ Interpret prefixes in config files to find the actual value. Also, "${config:format}" is replaced with the configured format ("rst" or "md"). Prefixes: "file:" read the content from a file. "literal:" read a literal string from a file. """ value = value.replace("${config:format}", self.format) if value.startswith("file:"): file_name = value.partition(":")[2].strip() file_path = Path(self.fragment_directory) / file_name if file_path.exists(): value = file_path.read_text() else: try: file_bytes = pkgutil.get_data( "scriv", "templates/" + file_name ) except IOError as err: msg = "No such file: {}".format(file_path) raise Exception(msg) from err assert file_bytes value = file_bytes.decode("utf-8") elif value.startswith("literal:"): _, file_name, literal_name = value.split(":", maxsplit=2) found = find_literal(file_name.strip(), literal_name.strip()) if found is None: > raise Exception("Couldn't find literal: {!r}".format(value)) E Exception: Couldn't find literal: 'literal:sub/foob.py: __version__' /Users/ned/scriv/.tox/py36/lib/python3.6/site-packages/scriv/config.py:303: Exception _____________________________________________________________________ test_find_python_literal[version-1.2.3] _____________________________________________________________________ name = 'version', value = '1.2.3', temp_dir = PosixPath('/private/var/folders/j2/gr3cj3jn63s5q8g3bjvw57hm0000gp/T/pytest-of-ned/pytest-7/test_find_python_literal_versi0') @pytest.mark.parametrize( "name, value", [ ("version", "1.2.3"), ("also", "xyzzy"), ("but", "hello there"), ("somewhere_else", "this would be an odd place to get the string"), ("a_thing_2", None), ("how_many", None), ], ) def test_find_python_literal(name, value, temp_dir): with open("foo.py", "w") as f: f.write(PYTHON_CODE) > assert find_literal("foo.py", name) == value E AssertionError: assert None == '1.2.3' E + where None = find_literal('foo.py', 'version') /Users/ned/scriv/tests/test_literals.py:48: AssertionError ______________________________________________________________________ test_find_python_literal[also-xyzzy] _______________________________________________________________________ name = 'also', value = 'xyzzy', temp_dir = PosixPath('/private/var/folders/j2/gr3cj3jn63s5q8g3bjvw57hm0000gp/T/pytest-of-ned/pytest-7/test_find_python_literal_also_0') @pytest.mark.parametrize( "name, value", [ ("version", "1.2.3"), ("also", "xyzzy"), ("but", "hello there"), ("somewhere_else", "this would be an odd place to get the string"), ("a_thing_2", None), ("how_many", None), ], ) def test_find_python_literal(name, value, temp_dir): with open("foo.py", "w") as f: f.write(PYTHON_CODE) > assert find_literal("foo.py", name) == value E AssertionError: assert None == 'xyzzy' E + where None = find_literal('foo.py', 'also') /Users/ned/scriv/tests/test_literals.py:48: AssertionError ____________________________________________________________________ test_find_python_literal[but-hello there] ____________________________________________________________________ name = 'but', value = 'hello there', temp_dir = PosixPath('/private/var/folders/j2/gr3cj3jn63s5q8g3bjvw57hm0000gp/T/pytest-of-ned/pytest-7/test_find_python_literal_but_h0') @pytest.mark.parametrize( "name, value", [ ("version", "1.2.3"), ("also", "xyzzy"), ("but", "hello there"), ("somewhere_else", "this would be an odd place to get the string"), ("a_thing_2", None), ("how_many", None), ], ) def test_find_python_literal(name, value, temp_dir): with open("foo.py", "w") as f: f.write(PYTHON_CODE) > assert find_literal("foo.py", name) == value E AssertionError: assert None == 'hello there' E + where None = find_literal('foo.py', 'but') /Users/ned/scriv/tests/test_literals.py:48: AssertionError ______________________________________________ test_find_python_literal[somewhere_else-this would be an odd place to get the string] ______________________________________________ name = 'somewhere_else', value = 'this would be an odd place to get the string' temp_dir = PosixPath('/private/var/folders/j2/gr3cj3jn63s5q8g3bjvw57hm0000gp/T/pytest-of-ned/pytest-7/test_find_python_literal_somew0') @pytest.mark.parametrize( "name, value", [ ("version", "1.2.3"), ("also", "xyzzy"), ("but", "hello there"), ("somewhere_else", "this would be an odd place to get the string"), ("a_thing_2", None), ("how_many", None), ], ) def test_find_python_literal(name, value, temp_dir): with open("foo.py", "w") as f: f.write(PYTHON_CODE) > assert find_literal("foo.py", name) == value E AssertionError: assert None == 'this would be an odd place to get the string' E + where None = find_literal('foo.py', 'somewhere_else') /Users/ned/scriv/tests/test_literals.py:48: AssertionError ============================================================================= short test summary info ============================================================================= FAILED tests/test_config.py::test_literal_reading - Exception: Couldn't find literal: 'literal:sub/foob.py: __version__' FAILED tests/test_literals.py::test_find_python_literal[version-1.2.3] - AssertionError: assert None == '1.2.3' FAILED tests/test_literals.py::test_find_python_literal[also-xyzzy] - AssertionError: assert None == 'xyzzy' FAILED tests/test_literals.py::test_find_python_literal[but-hello there] - AssertionError: assert None == 'hello there' FAILED tests/test_literals.py::test_find_python_literal[somewhere_else-this would be an odd place to get the string] - AssertionError: assert None == 'this would be an odd plac... ========================================================================== 5 failed, 81 passed in 1.86s =========================================================================== ERROR: InvocationError for command /Users/ned/scriv/.tox/py36/bin/coverage run -p -m pytest -Wd (exited with code 1) _____________________________________________________________________________________ summary _____________________________________________________________________________________ ERROR: py36: commands failed
Like this: