Ban spaces around filenames (bug 891899)

This commit is contained in:
Matt Basta 2013-07-10 16:57:32 -07:00
Родитель 3e595d39de
Коммит e46d0fcd57
3 изменённых файлов: 29 добавлений и 3 удалений

Просмотреть файл

@ -29,6 +29,19 @@ def test_blacklisted_files(err, package=None):
for name in package:
file_ = package.info(name)
if (file_["name_lower"].startswith(" ") or
file_["name_lower"].endswith(" ")):
err.error(
err_id=("packagelayout", "invalid_name"),
error="Filename starts with or ends with invalid character.",
description=["A filename within the package was found to "
"begin or end with a space. This is not "
"allowed.",
"Detected filename: '%s'" % name],
filename=name)
continue
# Simple test to ensure that the extension isn't blacklisted
extension = file_["extension"]
if extension in blacklisted_extensions:

Просмотреть файл

@ -169,6 +169,7 @@ class MockXPI:
return True
def info(self, name):
name = name.split('/')[-1]
return {"name_lower": name.lower(),
"extension": name.lower().split(".")[-1]}

Просмотреть файл

@ -32,16 +32,28 @@ def test_duplicate_files():
"""Test that duplicate files in a package are caught."""
package = MagicMock()
package.subpackage = False
zf = MagicMock()
package.zf = zf = MagicMock()
zf.namelist.return_value = ["foo.bar", "foo.bar"]
package.zf = zf
err = ErrorBundle()
packagelayout.test_layout_all(err, package)
assert err.failed()
def test_spaces_in_names():
"""Test that spaces in filenames are errors."""
package = MockXPI({
"foo/bar/foo.bar ": None,
"foo/bar/ foo.bar": None,
})
err = ErrorBundle()
packagelayout.test_blacklisted_files(err, package)
assert err.failed()
assert len(err.errors) == 2
class TestMETAINF(TestCase):
def setUp(self):