diff options
Diffstat (limited to 'tests/db/test_manager.py')
-rw-r--r-- | tests/db/test_manager.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/tests/db/test_manager.py b/tests/db/test_manager.py index e675aed4..02df63d9 100644 --- a/tests/db/test_manager.py +++ b/tests/db/test_manager.py @@ -9,12 +9,46 @@ import textwrap import os import shutil -from alot.db.manager import DBManager +import unittest +from unittest import mock + +from alot.db import manager from alot.settings.const import settings from notmuch import Database from .. import utilities +class TestIsSubdirOf(unittest.TestCase): + + def test_both_paths_absolute_matching(self): + superpath = '/a/b' + subpath = '/a/b/c/d.rst' + result = manager._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 = manager._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 = manager._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 = manager._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 = manager._is_subdir_of(subpath, superpath) + self.assertTrue(result) class TestDBManager(utilities.TestCaseClassCleanup): @@ -34,7 +68,7 @@ class TestDBManager(utilities.TestCaseClassCleanup): cls.dbpath = tempfile.mkdtemp() cls.db = Database(path=cls.dbpath, create=True) cls.db.close() - cls.manager = DBManager(cls.dbpath) + cls.manager = manager.DBManager(cls.dbpath) # clean up temporary database cls.addClassCleanup(cls.manager.kill_search_processes) |