input-remapper/tests/unit/test_paths.py

66 lines
2.2 KiB
Python
Raw Normal View History

2021-01-07 16:15:12 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
2022-01-01 12:00:49 +00:00
# input-remapper - GUI for device specific keyboard mappings
2022-01-01 12:52:33 +00:00
# Copyright (C) 2022 sezanzeb <proxima@sezanzeb.de>
2021-01-07 16:15:12 +00:00
#
2022-01-01 12:00:49 +00:00
# This file is part of input-remapper.
2021-01-07 16:15:12 +00:00
#
2022-01-01 12:00:49 +00:00
# input-remapper is free software: you can redistribute it and/or modify
2021-01-07 16:15:12 +00:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2022-01-01 12:00:49 +00:00
# input-remapper is distributed in the hope that it will be useful,
2021-01-07 16:15:12 +00:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2022-01-01 12:00:49 +00:00
# along with input-remapper. If not, see <https://www.gnu.org/licenses/>.
2021-01-07 16:15:12 +00:00
import os
import unittest
import tempfile
2021-01-07 16:15:12 +00:00
2022-01-01 12:00:49 +00:00
from inputremapper.paths import touch, mkdir, get_preset_path, get_config_path
2021-01-07 16:15:12 +00:00
from tests.test import quick_cleanup, tmp
2021-01-07 16:15:12 +00:00
2022-01-17 23:55:01 +00:00
2021-01-07 16:15:12 +00:00
def _raise(error):
raise error
class TestPaths(unittest.TestCase):
def tearDown(self):
quick_cleanup()
2021-01-07 16:15:12 +00:00
def test_touch(self):
with tempfile.TemporaryDirectory() as local_tmp:
path_abcde = os.path.join(local_tmp, "a/b/c/d/e")
touch(path_abcde)
self.assertTrue(os.path.exists(path_abcde))
self.assertTrue(os.path.isfile(path_abcde))
2022-01-17 23:55:01 +00:00
self.assertRaises(
ValueError, lambda: touch(os.path.join(local_tmp, "a/b/c/d/f/"))
)
2021-01-07 16:15:12 +00:00
def test_mkdir(self):
with tempfile.TemporaryDirectory() as local_tmp:
path_bcde = os.path.join(local_tmp, "b/c/d/e")
mkdir(path_bcde)
self.assertTrue(os.path.exists(path_bcde))
self.assertTrue(os.path.isdir(path_bcde))
2021-01-07 16:15:12 +00:00
def test_get_preset_path(self):
2021-09-26 10:44:56 +00:00
self.assertEqual(get_preset_path(), os.path.join(tmp, "presets"))
self.assertEqual(get_preset_path("a"), os.path.join(tmp, "presets/a"))
self.assertEqual(
get_preset_path("a", "b"), os.path.join(tmp, "presets/a/b.json")
)
2021-01-07 16:15:12 +00:00
def test_get_config_path(self):
self.assertEqual(get_config_path(), tmp)
2021-09-26 10:44:56 +00:00
self.assertEqual(get_config_path("a", "b"), os.path.join(tmp, "a/b"))