From 156aeda8a0c45009ddf9fe869e6b3bd9f485489f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Cioc=C3=AErlan?= Date: Tue, 7 Jan 2014 17:59:50 +0200 Subject: [PATCH] updated tests for filename shortening (which now returns relative paths) --- test/test_util_filenaming.py | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/test_util_filenaming.py b/test/test_util_filenaming.py index b7b2056fa..e04441ca5 100644 --- a/test/test_util_filenaming.py +++ b/test/test_util_filenaming.py @@ -17,7 +17,7 @@ class ShortFilenameTest(unittest.TestCase): def test_bmp_unicode_on_unicode_fs(self): char = u"\N{LATIN SMALL LETTER SHARP S}" fn = make_short_filename(self.root, os.path.join(*[char * 120] * 2)) - self.assertEqual(fn, os.path.join(self.root, *[char * 120] * 2)) + self.assertEqual(fn, os.path.join(*[char * 120] * 2)) @unittest.skipUnless(sys.platform not in ("win32", "darwin"), "non-windows, non-osx test") def test_bmp_unicode_on_nix(self): @@ -25,28 +25,28 @@ class ShortFilenameTest(unittest.TestCase): max_len = 255 divisor = len(char.encode(sys.getfilesystemencoding())) fn = make_short_filename(self.root, os.path.join(*[char * 200] * 2)) - self.assertEqual(fn, os.path.join(self.root, *[char * (max_len // divisor)] * 2)) + self.assertEqual(fn, os.path.join(*[char * (max_len // divisor)] * 2)) @unittest.skipUnless(sys.platform == "darwin", "os x test") def test_precomposed_unicode_on_osx(self): char = u"\N{LATIN SMALL LETTER A WITH BREVE}" max_len = 255 fn = make_short_filename(self.root, os.path.join(*[char * 200] * 2)) - self.assertEqual(fn, os.path.join(self.root, *[char * (max_len // 2)] * 2)) + self.assertEqual(fn, os.path.join(*[char * (max_len // 2)] * 2)) @unittest.skipUnless(sys.platform == "win32", "windows test") def test_nonbmp_unicode_on_windows(self): char = u"\N{MUSICAL SYMBOL G CLEF}" remaining = 259 - (3 + 10 + 1 + 200 + 1) fn = make_short_filename(self.root, os.path.join(*[char * 100] * 2)) - self.assertEqual(fn, os.path.join(self.root, char * 100, char * (remaining // 2))) + self.assertEqual(fn, os.path.join(char * 100, char * (remaining // 2))) @unittest.skipUnless(sys.platform == "darwin", "os x test") def test_nonbmp_unicode_on_osx(self): char = u"\N{MUSICAL SYMBOL G CLEF}" max_len = 255 fn = make_short_filename(self.root, os.path.join(*[char * 200] * 2)) - self.assertEqual(fn, os.path.join(self.root, *[char * (max_len // 2)] * 2)) + self.assertEqual(fn, os.path.join(*[char * (max_len // 2)] * 2)) @unittest.skipUnless(sys.platform not in ("win32", "darwin"), "non-windows, non-osx test") def test_nonbmp_unicode_on_nix(self): @@ -54,7 +54,7 @@ class ShortFilenameTest(unittest.TestCase): max_len = 255 divisor = len(char.encode(sys.getfilesystemencoding())) fn = make_short_filename(self.root, os.path.join(*[char * 100] * 2)) - self.assertEqual(fn, os.path.join(self.root, *[char * (max_len // divisor)] * 2)) + self.assertEqual(fn, os.path.join(*[char * (max_len // divisor)] * 2)) @unittest.skipUnless(sys.platform not in ("win32", "darwin"), "non-windows, non-osx test") def test_nonbmp_unicode_on_nix_with_windows_compat(self): @@ -63,45 +63,49 @@ class ShortFilenameTest(unittest.TestCase): remaining = 259 - (3 + 10 + 1 + 200 + 1) divisor = len(char.encode(sys.getfilesystemencoding())) fn = make_short_filename(self.root, os.path.join(*[char * 100] * 2), win_compat=True) - self.assertEqual(fn, os.path.join(self.root, char * (max_len // divisor), char * (remaining // 2))) + self.assertEqual(fn, os.path.join(char * (max_len // divisor), char * (remaining // 2))) def test_windows_shortening(self): fn = make_short_filename(self.root, os.path.join("a" * 200, "b" * 200, "c" * 200 + ".ext"), win_compat=True) - self.assertEqual(fn, os.path.join(self.root, "a" * 116, "b" * 116, "c" * 7 + ".ext")) + self.assertEqual(fn, os.path.join("a" * 116, "b" * 116, "c" * 7 + ".ext")) @unittest.skipUnless(sys.platform != "win32", "non-windows test") def test_windows_shortening_with_ancestor_on_nix(self): + root = os.path.join(self.root, "w" * 10, "x" * 10, "y" * 9, "z" * 9) fn = make_short_filename( - os.path.join(self.root, "w" * 10, "x" * 10, "y" * 9, "z" * 9), os.path.join("b" * 200, "c" * 200, "d" * 200 + ".ext"), + root, os.path.join("b" * 200, "c" * 200, "d" * 200 + ".ext"), win_compat=True, relative_to = self.root) - self.assertEqual(fn, os.path.join(self.root, "w" * 10, "x" * 10, "y" * 9, "z" * 9, "b" * 100, "c" * 100, "d" * 7 + ".ext")) + self.assertEqual(fn, os.path.join("b" * 100, "c" * 100, "d" * 7 + ".ext")) def test_windows_node_maxlength_shortening(self): max_len = 226 remaining = 259 - (3 + 10 + 1 + max_len + 1) fn = make_short_filename(self.root, os.path.join("a" * 300, "b" * 100 + ".ext"), win_compat=True) - self.assertEqual(fn, os.path.join(self.root, "a" * max_len, "b" * (remaining - 4) + ".ext")) + self.assertEqual(fn, os.path.join("a" * max_len, "b" * (remaining - 4) + ".ext")) def test_windows_selective_shortening(self): root = self.root + "x" * (44 - 10 - 3) fn = make_short_filename(root, os.path.join( os.path.join(*["a" * 9] * 10 + ["b" * 15] * 10), "c" * 10), win_compat=True) - self.assertEqual(fn, os.path.join(root, os.path.join(*["a" * 9] * 10 + ["b" * 9] * 10), "c" * 10)) + self.assertEqual(fn, os.path.join(os.path.join(*["a" * 9] * 10 + ["b" * 9] * 10), "c" * 10)) def test_windows_shortening_not_needed(self): - fn = make_short_filename(self.root + "x" * 33, os.path.join( + root = self.root + "x" * 33 + fn = make_short_filename(root, os.path.join( os.path.join(*["a" * 9] * 20), "b" * 10), win_compat=True) - self.assertEqual(fn, os.path.join(self.root + "x" * 33, os.path.join(*["a" * 9] * 20), "b" * 10)) + self.assertEqual(fn, os.path.join(os.path.join(*["a" * 9] * 20), "b" * 10)) def test_windows_path_too_long(self): + root = self.root + "x" * 230 self.assertRaises(IOError, make_short_filename, - self.root + "x" * 230, os.path.join("a", "b", "c", "d"), win_compat=True) + root, os.path.join("a", "b", "c", "d"), win_compat=True) def test_windows_path_not_too_long(self): - fn = make_short_filename(self.root + "x" * 230, os.path.join("a", "b", "c"), win_compat=True) - self.assertEqual(fn, os.path.join(self.root + "x" * 230, "a", "b", "c")) + root = self.root + "x" * 230 + fn = make_short_filename(root, os.path.join("a", "b", "c"), win_compat=True) + self.assertEqual(fn, os.path.join("a", "b", "c")) def test_whitespace(self): fn = make_short_filename(self.root, os.path.join("a1234567890 ", " b1234567890 ")) - self.assertEqual(fn, os.path.join(self.root, "a1234567890", "b1234567890")) + self.assertEqual(fn, os.path.join("a1234567890", "b1234567890"))