aboutsummaryrefslogtreecommitdiff
path: root/test/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_utils.py')
-rw-r--r--test/test_utils.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index eb0af703f..0a435ddc5 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -22,17 +22,43 @@ class TestUtil(unittest.TestCase):
self.assertEqual(sanitize_filename(u'123'), u'123')
- self.assertEqual(u'abc_de', sanitize_filename(u'abc/de'))
- self.assertTrue(u'de' in sanitize_filename(u'abc/de'))
+ self.assertEqual(u'abc-de', sanitize_filename(u'abc/de'))
self.assertFalse(u'/' in sanitize_filename(u'abc/de///'))
- self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de'))
- self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de'))
- self.assertTrue(u'de' in sanitize_filename(u'abc\\de'))
+ self.assertEqual(u'abc-de', sanitize_filename(u'abc/<>\\*|de'))
+ self.assertEqual(u'xxx', sanitize_filename(u'xxx/<>\\*|'))
+ self.assertEqual(u'yes no', sanitize_filename(u'yes? no'))
+ self.assertEqual(u'this - that', sanitize_filename(u'this: that'))
+ self.assertEqual(sanitize_filename(u'AT&T'), u'AT&T')
self.assertEqual(sanitize_filename(u'ä'), u'ä')
self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица')
+ forbidden = u'"\0\\/'
+ for fc in forbidden:
+ for fbc in forbidden:
+ self.assertTrue(fbc not in sanitize_filename(fc))
+
+ def test_sanitize_filename_restricted(self):
+ self.assertEqual(sanitize_filename(u'abc', restricted=True), u'abc')
+ self.assertEqual(sanitize_filename(u'abc_d-e', restricted=True), u'abc_d-e')
+
+ self.assertEqual(sanitize_filename(u'123', restricted=True), u'123')
+
+ self.assertEqual(u'abc-de', sanitize_filename(u'abc/de', restricted=True))
+ self.assertFalse(u'/' in sanitize_filename(u'abc/de///', restricted=True))
+
+ self.assertEqual(u'abc-de', sanitize_filename(u'abc/<>\\*|de', restricted=True))
+ self.assertEqual(u'xxx', sanitize_filename(u'xxx/<>\\*|', restricted=True))
+ self.assertEqual(u'yes_no', sanitize_filename(u'yes? no', restricted=True))
+ self.assertEqual(u'this_-_that', sanitize_filename(u'this: that', restricted=True))
+
+ forbidden = u'"\0\\/&: \'\t\n'
+ for fc in forbidden:
+ print('input: ' + fc + ', result: ' + repr(sanitize_filename(fc, restricted=True)))
+ for fbc in forbidden:
+ self.assertTrue(fbc not in sanitize_filename(fc, restricted=True))
+
def test_ordered_set(self):
self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7])
self.assertEqual(orderedSet([]), [])