Beispiel #1
0
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
    assert text == "12.34.56"
Beispiel #2
0
 def test_new_fragment_contents_md(self):
     config = Config(format="md")
     contents = new_fragment_contents(config)
     assert contents.startswith("<!--")
     assert "A new scriv changelog fragment" in contents
     assert "### Added\n" in contents
     assert all(cat in contents for cat in config.categories)
Beispiel #3
0
 def test_new_fragment_contents_rst(self):
     config = Config(format="rst")
     contents = new_fragment_contents(config)
     assert contents.startswith(".. ")
     assert ".. A new scriv changelog fragment" in contents
     assert ".. Added\n.. -----\n" in contents
     assert all(cat in contents for cat in config.categories)
Beispiel #4
0
def test_no_such_template():
    # If you specify a template name, and it doesn't exist, an error will
    # be raised.
    msg = r"No such file: changelog\.d[/\\]foo\.j2"
    with pytest.raises(Exception, match=msg):
        config = Config(new_fragment_template="file: foo.j2")
        config.new_fragment_template  # pylint: disable=pointless-statement
Beispiel #5
0
 def test_new_fragment_contents_md(self):
     scriv = Scriv(config=Config(format="md"))
     content = scriv.new_fragment().content
     assert content.startswith("<!--")
     assert "A new scriv changelog fragment" in content
     assert "### Added\n" in content
     assert all(cat in content for cat in scriv.config.categories)
Beispiel #6
0
 def test_new_fragment_contents_rst_with_customized_header(self):
     scriv = Scriv(config=Config(format="rst", rst_header_chars="#~"))
     content = scriv.new_fragment().content
     assert content.startswith(".. ")
     assert ".. A new scriv changelog fragment" in content
     assert ".. Added\n.. ~~~~~\n" in content
     assert all(cat in content for cat in scriv.config.categories)
Beispiel #7
0
 def test_new_fragment_contents_rst(self):
     scriv = Scriv(config=Config(format="rst"))
     content = scriv.new_fragment().content
     assert content.startswith(".. ")
     assert ".. A new scriv changelog fragment" in content
     assert ".. Added\n.. -----\n" in content
     assert all(cat in content for cat in scriv.config.categories)
Beispiel #8
0
 def test_new_fragment_path_with_custom_main(self, fake_git):
     fake_git.set_config("github.user", "joedev")
     fake_git.set_branch("mainline")
     config = Config(fragment_directory="notes",
                     main_branches=["main", "mainline"])
     assert new_fragment_path(config) == Path(
         "notes/20121001_070809_joedev.rst")
Beispiel #9
0
 def test_new_fragment_contents_rst_with_customized_header(self):
     config = Config(format="rst", rst_header_chars="#~")
     contents = new_fragment_contents(config)
     assert contents.startswith(".. ")
     assert ".. A new scriv changelog fragment" in contents
     assert ".. Added\n.. ~~~~~\n" in contents
     assert all(cat in contents for cat in config.categories)
Beispiel #10
0
 def test_no_categories_rst(self, changelog_d):
     # If the project isn't using categories, then the new fragment is
     # simpler with no heading.
     config = Config(categories="")
     contents = new_fragment_contents(config)
     assert ".. A new scriv changelog fragment." in contents
     assert "- A bullet item for this fragment. EDIT ME!" in contents
     assert "Uncomment the header that is right" not in contents
     assert ".. Added" not in contents
Beispiel #11
0
def test_literal_no_literal(temp_dir):
    # What happens if the literal we're looking for isn't there?
    (temp_dir / "sub").mkdir()
    (temp_dir / "sub" /
     "foob.py").write_text("""# comment\n__version__ = "12.34.56"\n""")
    with pytest.raises(
            Exception,
            match=r"Couldn't find literal: 'literal:sub/foob.py: version'",
    ):
        Config(version="literal:sub/foob.py: version")
Beispiel #12
0
 def test_new_fragment_path(self, fake_git):
     fake_git.set_config("github.user", "joedev")
     fake_git.set_branch("master")
     config = Config(fragment_directory="notes")
     assert new_fragment_path(config) == Path(
         "notes/20121001_070809_joedev.rst")
Beispiel #13
0
def test_format_header(config_kwargs, text, result):
    actual = RstTools(Config(**config_kwargs)).format_header(text)
    assert actual == result
Beispiel #14
0
def test_format_sections(sections, expected):
    sections = collections.OrderedDict(sections)
    actual = RstTools(Config(rst_header_chars="#~")).format_sections(sections)
    assert actual == textwrap.dedent(expected)
Beispiel #15
0
def test_rst_chars_is_two_chars(chars):
    # rst_header_chars must be exactly two non-space characters.
    with pytest.raises(ValueError):
        Config(rst_header_chars=chars)
Beispiel #16
0
def test_override_default_name(changelog_d):
    # You can define a file named new_fragment.rst.j2, and it will be read
    # as the template.
    (changelog_d / "new_fragment.rst.j2").write_text("Hello there!")
    fmt = Config().new_fragment_template
    assert fmt == "Hello there!"
Beispiel #17
0
def test_unknown_format():
    with pytest.raises(
            ValueError,
            match=r"'format' must be in \['rst', 'md'\] \(got 'xyzzy'\)"):
        Config(format="xyzzy")
Beispiel #18
0
def test_custom_template(changelog_d):
    # You can define your own template with your own name.
    (changelog_d / "start_here.j2").write_text("Custom template.")
    fmt = Config(
        new_fragment_template="file: start_here.j2").new_fragment_template
    assert fmt == "Custom template."
Beispiel #19
0
 def test_new_fragment_path_with_branch(self, fake_git):
     fake_git.set_config("github.user", "joedev")
     fake_git.set_branch("joedeveloper/feature-123.4")
     config = Config(fragment_directory="notes")
     assert new_fragment_path(config) == Path(
         "notes/20130225_151617_joedev_feature_123_4.rst")
Beispiel #20
0
def test_file_reading(changelog_d):
    # Any setting can be read from a file, even where it doesn't make sense.
    (changelog_d / "hello.txt").write_text("Xyzzy")
    text = Config(output_file="file:hello.txt").output_file
    assert text == "Xyzzy"
Beispiel #21
0
def test_no_such_template():
    # If you specify a template name, and it doesn't exist, an error will
    # be raised.
    with pytest.raises(Exception, match="No such file: changelog.d/foo.j2"):
        Config(new_fragment_template="file: foo.j2")
Beispiel #22
0
def test_literal_no_file():
    # What happens if the file for a literal doesn't exist?
    with pytest.raises(FileNotFoundError,
                       match=r"No such file or directory: 'sub/foob.py'"):
        config = Config(version="literal:sub/foob.py: __version__")
        config.version  # pylint: disable=pointless-statement
Beispiel #23
0
def test_format_sections(sections, expected):
    sections = collections.OrderedDict(sections)
    actual = MdTools(Config(md_header_level="2")).format_sections(sections)
    assert actual == textwrap.dedent(expected)
Beispiel #24
0
def test_literal_no_file(temp_dir):
    # What happens if the file for a literal doesn't exist?
    with pytest.raises(FileNotFoundError,
                       match=r"No such file or directory: 'sub/foob.py'"):
        Config(version="literal:sub/foob.py: __version__")