提交 07de4881 编写于 作者: L Lukáš Doktor

avocado.utils.astring: Replace the leading "."

The leading "." makes files invisible on unix systems, which might be
confusing to users. Let's replace with "_".
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 63fbe1a8
......@@ -217,4 +217,6 @@ def string_to_safe_path(string):
:param string: String to be converted
:return: String which is safe to pass as a file/dir name (on recent fs)
"""
if string.startswith("."):
string = "_" + string[1:]
return string.replace(os.path.sep, '_')[:255]
......@@ -34,6 +34,31 @@ class TestClassTestUnit(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tmpdir)
def testUglyName(self):
def run(name, path_name):
""" Initialize test and check the dirs were created """
test = DummyTest("test", name, base_logdir=self.tmpdir)
self.assertEqual(os.path.basename(test.logdir), path_name)
self.assertTrue(os.path.exists(test.logdir))
self.assertEqual(os.path.dirname(os.path.dirname(test.logdir)),
self.tmpdir)
run("/absolute/path", "_absolute_path")
run("./relative/path", "__relative_path")
run("../../multi_level/relative/path",
"_._.._multi_level_relative_path")
# Greek word 'kosme'
run("\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5",
"\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5")
# Particularly problematic noncharacters in 16-bit applications
name = ("\xb7\x95\xef\xb7\x96\xef\xb7\x97\xef\xb7\x98\xef\xb7\x99"
"\xef\xb7\x9a\xef\xb7\x9b\xef\xb7\x9c\xef\xb7\x9d\xef\xb7"
"\x9e\xef\xb7\x9f\xef\xb7\xa0\xef\xb7\xa1\xef\xb7\xa2\xef"
"\xb7\xa3\xef\xb7\xa4\xef\xb7\xa5\xef\xb7\xa6\xef\xb7\xa7"
"\xef\xb7\xa8\xef\xb7\xa9\xef\xb7\xaa\xef\xb7\xab\xef\xb7"
"\xac\xef\xb7\xad\xef\xb7\xae\xef\xb7\xaf")
run(name, name)
def testLongName(self):
test = DummyTest("test", "a" * 256, base_logdir=self.tmpdir)
self.assertEqual(os.path.basename(test.logdir), "a" * 250)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册