From 07de4881446f838b0d3a2a903782bda056dbc7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Sun, 10 Apr 2016 21:28:49 +0200 Subject: [PATCH] avocado.utils.astring: Replace the leading "." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The leading "." makes files invisible on unix systems, which might be confusing to users. Let's replace with "_". Signed-off-by: Lukáš Doktor --- avocado/utils/astring.py | 2 ++ selftests/unit/test_test.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/avocado/utils/astring.py b/avocado/utils/astring.py index dfa15a87..eb18ad52 100644 --- a/avocado/utils/astring.py +++ b/avocado/utils/astring.py @@ -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] diff --git a/selftests/unit/test_test.py b/selftests/unit/test_test.py index 1a3123fb..b11f847e 100644 --- a/selftests/unit/test_test.py +++ b/selftests/unit/test_test.py @@ -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) -- GitLab