diff options
author | Lucas Hoffmann <l-m-h@web.de> | 2017-06-09 09:19:39 +0200 |
---|---|---|
committer | Lucas Hoffmann <l-m-h@web.de> | 2017-06-21 09:17:55 +0200 |
commit | 20cd2a8fe0f256411ce176b15e26cdc95d19ab3c (patch) | |
tree | cafde370c76b467b74e3e6e267cf38351c6c18f7 /tests/db/utils_test.py | |
parent | a30b26501422e73728f3bed61e705f1df08f2f35 (diff) |
Add test for db.utils.is_subdir_of
Diffstat (limited to 'tests/db/utils_test.py')
-rw-r--r-- | tests/db/utils_test.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/db/utils_test.py b/tests/db/utils_test.py index 60d0304e..1ca127a3 100644 --- a/tests/db/utils_test.py +++ b/tests/db/utils_test.py @@ -5,6 +5,8 @@ from __future__ import absolute_import import email +import os +import os.path import unittest from alot.db import utils @@ -57,3 +59,35 @@ class TestGetParams(unittest.TestCase): expected = dict(failobj) self.assertEqual(actual, expected) + +class TestIsSubdirOf(unittest.TestCase): + + def test_both_paths_absolute_matching(self): + superpath = '/a/b' + subpath = '/a/b/c/d.rst' + result = utils.is_subdir_of(subpath, superpath) + self.assertTrue(result) + + def test_both_paths_absolute_not_matching(self): + superpath = '/a/z' + subpath = '/a/b/c/d.rst' + result = utils.is_subdir_of(subpath, superpath) + self.assertFalse(result) + + def test_both_paths_relative_matching(self): + superpath = 'a/b' + subpath = 'a/b/c/d.rst' + result = utils.is_subdir_of(subpath, superpath) + self.assertTrue(result) + + def test_both_paths_relative_not_matching(self): + superpath = 'a/z' + subpath = 'a/b/c/d.rst' + result = utils.is_subdir_of(subpath, superpath) + self.assertFalse(result) + + def test_relative_path_and_absolute_path_matching(self): + superpath = 'a/b' + subpath = os.path.join(os.getcwd(), 'a/b/c/d.rst') + result = utils.is_subdir_of(subpath, superpath) + self.assertTrue(result) |