Beispiel #1
0
 def test_no_toml_installed(self, temp_dir):
     # Without toml installed, raise an error if we have settings in the toml
     # file.
     (temp_dir / "pyproject.toml").write_text(TOML_CONFIG)
     with without_module(scriv.config, "tomli"):
         msg_pat = r"Can't read .* without TOML support"
         with pytest.raises(Exception, match=msg_pat):
             Config.read()
Beispiel #2
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 #3
0
 def test_no_toml_installed_no_settings(self, temp_dir):
     # Without toml installed, and also none of our settings in the toml
     # file, there is no exception.
     (temp_dir / "pyproject.toml").write_text(GENERIC_TOML_CONFIG)
     with without_module(scriv.config, "tomli"):
         config = Config.read()
     assert config.categories[0] == "Removed"
Beispiel #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
0
def test_reading_config_from_other_directory(temp_dir):
    # setup.cfg can set the fragment directory, and then scriv.ini will
    # be found there.
    (temp_dir / "scriv.d").mkdir()
    (temp_dir / "scriv.d" / "scriv.ini").write_text(CONFIG1)
    (temp_dir /
     "setup.cfg").write_text("[tool.scriv]\nfragment_directory = scriv.d\n")
    config = Config.read()
    assert config.fragment_directory == "scriv.d"
    assert config.categories == ["New", "Different", "Gone", "Bad"]
Beispiel #14
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 #15
0
 def test_toml_without_us(self, temp_dir):
     (temp_dir / "pyproject.toml").write_text(GENERIC_TOML_CONFIG)
     config = Config.read()
     assert config.categories == [
         "Removed",
         "Added",
         "Changed",
         "Deprecated",
         "Fixed",
         "Security",
     ]
Beispiel #16
0
def test_defaults(temp_dir):
    # No configuration files anywhere, just get all the defaults.
    config = Config.read()
    assert config.fragment_directory == "changelog.d"
    assert config.format == "rst"
    assert config.new_fragment_template.startswith(
        ".. A new scriv changelog fragment")
    assert config.categories == [
        "Removed",
        "Added",
        "Changed",
        "Deprecated",
        "Fixed",
        "Security",
    ]
    assert config.output_file == "CHANGELOG.rst"
    assert config.insert_marker == "scriv-insert-here"
    assert config.rst_header_chars == "=-"
    assert config.md_header_level == "1"
    assert "{{ date.strftime('%Y-%m-%d') }}" in config.entry_title_template
    assert config.main_branches == ["master", "main", "develop"]
    assert config.version == ""
Beispiel #17
0
def test_md_format(changelog_d):
    (changelog_d / "scriv.ini").write_text("[scriv]\nformat = md\n")
    config = Config.read()
    assert config.output_file == "CHANGELOG.md"
    template = re.sub(r"\s+", " ", config.new_fragment_template)
    assert template.startswith("<!-- A new scriv changelog fragment.")
Beispiel #18
0
def test_unknown_option():
    config = Config.read()
    expected = "Scriv configuration has no 'foo' option"
    with pytest.raises(AttributeError, match=expected):
        config.foo  # pylint: disable=pointless-statement
Beispiel #19
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 #20
0
def test_unknown_format():
    with pytest.raises(
            ValueError,
            match=r"'format' must be in \['rst', 'md'\] \(got 'xyzzy'\)"):
        Config(format="xyzzy")
Beispiel #21
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 #22
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 #23
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 #24
0
def test_format_header(config_kwargs, text, result):
    actual = RstTools(Config(**config_kwargs)).format_header(text)
    assert actual == result
Beispiel #25
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 #26
0
def test_reading_config(temp_dir):
    (temp_dir / "setup.cfg").write_text(CONFIG1)
    config = Config.read()
    assert config.fragment_directory == "changelog.d"
    assert config.output_file == "README.md"
    assert config.categories == ["New", "Different", "Gone", "Bad"]
Beispiel #27
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 #28
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 #29
0
 def test_reading_toml_file(self, temp_dir):
     (temp_dir / "pyproject.toml").write_text(TOML_CONFIG)
     config = Config.read()
     assert config.categories == ["New", "Different", "Gone", "Bad"]
Beispiel #30
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)