summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-12-01 20:11:27 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-12-01 20:12:35 (GMT)
commit1c9e36639b949cc765dab316825f9fec7af85a6e (patch)
tree862c1aaf89f31972930b5c938ae49cee4bb724ec /tests
parent99f653189e448b3ff3f2f02ab876231d44fa1ce3 (diff)
Computed relative and absolute paths.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/__init__.py0
-rw-r--r--tests/common/pathname.py95
2 files changed, 95 insertions, 0 deletions
diff --git a/tests/common/__init__.py b/tests/common/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/common/__init__.py
diff --git a/tests/common/pathname.py b/tests/common/pathname.py
new file mode 100644
index 0000000..5cd238c
--- /dev/null
+++ b/tests/common/pathname.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python3-dbg
+# -*- coding: utf-8 -*-
+
+
+# Tests minimalistes pour valider la construction de chemins relatifs et absolus.
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.common import pathname
+
+
+class TestRestrictedContent(ChrysalideTestCase):
+ """TestCase for common.pathname.build*"""
+
+ @classmethod
+ def setUpClass(cls):
+
+ super(TestRestrictedContent, cls).setUpClass()
+
+ cls._tests = [
+ {
+ 'ref' : '/a/b/d',
+ 'target' : '/a/b/e/f',
+ 'relative' : 'e/f'
+ },
+ {
+ 'ref' : '/a/b/c/d',
+ 'target' : '/a/b/f',
+ 'relative' : '../f'
+ },
+ {
+ 'ref' : '/a/b/c/d',
+ 'target' : '/a/b/c/e',
+ 'relative' : 'e'
+ },
+ {
+ 'ref' : '/a/bb/c/d',
+ 'target' : '/a/b/e/f',
+ 'relative' : '../../b/e/f'
+ },
+ {
+ 'ref' : '/a/b/c/d',
+ 'target' : '/a/bb/e/f',
+ 'relative' : '../../bb/e/f'
+ },
+ {
+ 'ref' : '/a/b/c/d',
+ 'target' : '/f',
+ 'relative' : '../../../f'
+ },
+ {
+ 'ref' : '/z/b/c/d',
+ 'target' : '/a/b/e/f',
+ 'relative' : '../../../a/b/e/f'
+ },
+ {
+ 'ref' : '/a/bbb/c/d',
+ 'target' : '/a/bbc/e/f',
+ 'relative' : '../../bbc/e/f'
+ }
+ ]
+
+
+ def testBuildingRelative(self):
+ """Build valid relative paths."""
+
+ build_relative = pathname.build_relative_filename
+
+ for tst in self._tests:
+
+ got = build_relative(tst['ref'], tst['target'])
+
+ self.assertEqual(got, tst['relative'])
+
+
+ def testBuildingAbsolute(self):
+ """Build valid absolute paths."""
+
+ build_absolute = pathname.build_absolute_filename
+
+ for tst in self._tests:
+
+ got = build_absolute(tst['ref'], tst['relative'])
+
+ self.assertEqual(got, tst['target'])
+
+
+ def testBuildingWrongAbsolute(self):
+ """Build invalid absolute paths."""
+
+ build_absolute = pathname.build_absolute_filename
+
+ with self.assertRaisesRegex(Exception, 'Relative path is too deep.'):
+
+ got = build_absolute('/a/b', '../../c')