Esempio n. 1
0
def test_getpaths_extra_absolute(tmp_path, charmcraft_yaml):
    """All extra files must be relative to the project."""
    charmcraft_yaml(prime=['/tmp/foobar'])
    with patch.object(pack, 'MANDATORY_FILES', []):
        with pytest.raises(CommandError) as cm:
            get_paths_to_include(tmp_path)
    assert str(
        cm.value
    ) == "Extra files in prime config can not be absolute: '/tmp/foobar'"
Esempio n. 2
0
def test_getpaths_extra_globstar_specific_files(tmp_path, config):
    """Combination of both mechanisms."""
    config.set(prime=['lib/**/*.txt'])
    srcpaths = (
        ('lib/foo/f1.txt', True),
        ('lib/foo/f1.nop', False),
        ('lib/foo/deep/fx.txt', True),
        ('lib/foo/deep/fx.nop', False),
        ('lib/bar/f2.txt', True),
        ('lib/bar/f2.nop', False),
        ('lib/f3.txt', True),
        ('lib/f3.nop', False),
        ('extra/lib/f.txt', False),
        ('libs/fs.nop', False),
    )
    allexpected = []
    for srcpath, expected in srcpaths:
        testfile = tmp_path / pathlib.Path(srcpath)
        testfile.parent.mkdir(parents=True, exist_ok=True)
        testfile.touch()
        if expected:
            allexpected.append(testfile)

    with patch.object(pack, 'MANDATORY_FILES', []):
        result = get_paths_to_include(config)
    assert result == sorted(allexpected)
Esempio n. 3
0
def test_getpaths_extra_long_path(tmp_path, config):
    """An extra file can be deep in directories."""
    config.set(prime=['foo/bar/baz/extra.txt'])
    testfile = tmp_path / 'foo' / 'bar' / 'baz' / 'extra.txt'
    testfile.parent.mkdir(parents=True)
    testfile.touch()

    with patch.object(pack, 'MANDATORY_FILES', []):
        result = get_paths_to_include(config)
    assert result == [testfile]
Esempio n. 4
0
def test_getpaths_mandatory_ok(tmp_path, config):
    """Simple succesful case getting all mandatory files."""
    test_mandatory = ['foo.txt', 'bar.bin']
    test_file1 = (tmp_path / 'foo.txt')
    test_file1.touch()
    test_file2 = (tmp_path / 'bar.bin')
    test_file2.touch()

    with patch.object(pack, 'MANDATORY_FILES', test_mandatory):
        result = get_paths_to_include(config)

    assert result == [test_file2, test_file1]
Esempio n. 5
0
def test_getpaths_mandatory_ok(tmp_path, config):
    """Simple succesful case getting all mandatory files."""
    test_mandatory = ["foo.txt", "bar.bin"]
    test_file1 = tmp_path / "foo.txt"
    test_file1.touch()
    test_file2 = tmp_path / "bar.bin"
    test_file2.touch()

    with patch.object(pack, "MANDATORY_FILES", test_mandatory):
        result = get_paths_to_include(config)

    assert result == [test_file2, test_file1]
Esempio n. 6
0
def test_getpaths_extra_wildcards_not_found(tmp_path, caplog, config):
    """Use wildcards to specify several files but nothing found."""
    caplog.set_level(logging.DEBUG, logger="charmcraft.commands")

    config.set(prime=['*.txt'])

    with patch.object(pack, 'MANDATORY_FILES', []):
        result = get_paths_to_include(config)
    assert result == []

    expected = [
        "Including per prime config '*.txt': [].",
    ]
    assert expected == [rec.message for rec in caplog.records]
Esempio n. 7
0
def test_getpaths_extra_missing(tmp_path, caplog, config):
    """Extra files were indicated but not found."""
    caplog.set_level(logging.DEBUG, logger="charmcraft.commands")

    config.set(prime=['f2.txt', 'f1.txt'])
    testfile1 = tmp_path / 'f1.txt'
    testfile1.touch()

    with patch.object(pack, 'MANDATORY_FILES', []):
        result = get_paths_to_include(config)
    assert result == [testfile1]

    expected = [
        "Including per prime config 'f2.txt': [].",
        "Including per prime config 'f1.txt': {}.".format([testfile1]),
    ]
    assert expected == [rec.message for rec in caplog.records]
Esempio n. 8
0
def test_getpaths_extra_ok(tmp_path, caplog, config):
    """Extra files were indicated ok."""
    caplog.set_level(logging.DEBUG, logger="charmcraft.commands")

    config.set(prime=["f2.txt", "f1.txt"])
    testfile1 = tmp_path / "f1.txt"
    testfile1.touch()
    testfile2 = tmp_path / "f2.txt"
    testfile2.touch()

    with patch.object(pack, "MANDATORY_FILES", []):
        result = get_paths_to_include(config)
    assert result == [testfile1, testfile2]

    expected = [
        "Including per prime config 'f2.txt': {}.".format([testfile2]),
        "Including per prime config 'f1.txt': {}.".format([testfile1]),
    ]
    assert expected == [rec.message for rec in caplog.records]
Esempio n. 9
0
def test_getpaths_extra_wildcards_ok(tmp_path, caplog, config):
    """Use wildcards to specify several files ok."""
    caplog.set_level(logging.DEBUG, logger="charmcraft.commands")

    config.set(prime=['*.txt'])
    testfile1 = tmp_path / 'f1.txt'
    testfile1.touch()
    testfile2 = tmp_path / 'f2.bin'
    testfile2.touch()
    testfile3 = tmp_path / 'f3.txt'
    testfile3.touch()

    with patch.object(pack, 'MANDATORY_FILES', []):
        result = get_paths_to_include(config)
    assert result == [testfile1, testfile3]

    expected = [
        "Including per prime config '*.txt': {}.".format([testfile1, testfile3]),
    ]
    assert expected == [rec.message for rec in caplog.records]
Esempio n. 10
0
def test_getpaths_extra_globstar(tmp_path, config):
    """Double star means whatever directories are in the path."""
    config.set(prime=['lib/**/*'])
    srcpaths = (
        ('lib/foo/f1.txt', True),
        ('lib/foo/deep/fx.txt', True),
        ('lib/bar/f2.txt', True),
        ('lib/f3.txt', True),
        ('extra/lib/f.txt', False),
        ('libs/fs.txt', False),
    )
    allexpected = []
    for srcpath, expected in srcpaths:
        testfile = tmp_path / pathlib.Path(srcpath)
        testfile.parent.mkdir(parents=True, exist_ok=True)
        testfile.touch()
        if expected:
            allexpected.append(testfile)

    with patch.object(pack, 'MANDATORY_FILES', []):
        result = get_paths_to_include(config)
    assert result == sorted(allexpected)