File: test_utils.py

package info (click to toggle)
ttkthemes 3.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,808 kB
  • sloc: tcl: 6,475; python: 773; makefile: 18
file content (58 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Author: RedFantom
License: GNU GPLv3
Copyright (c) 2017-2018 RedFantom
"""
from unittest import TestCase
from ttkthemes import _utils as utils
import os


class TestUtils(TestCase):
    def assertPathEquals(self, a, b):
        if hasattr(os.path, 'samefile'):
            self.assertTrue(os.path.samefile(a, b))
        else:
            # On windows, os.path.normcase lowercases because 'ASD' and 'asd'
            # should be treated equally
            self.assertEqual(os.path.normcase(a), os.path.normcase(b))

    def test_temporary_chdir(self):
        dir1 = os.getcwd()
        with utils.temporary_chdir(utils.get_temp_directory()):
            dir2 = os.getcwd()
        dir3 = os.getcwd()
        self.assertPathEquals(dir1, dir3)
        self.assertPathEquals(dir2, utils.get_temp_directory())

        with self.assertRaises(RuntimeError):
            with utils.temporary_chdir(utils.get_temp_directory()):
                raise RuntimeError()
        dir4 = os.getcwd()
        self.assertPathEquals(dir1, dir4)

    def test_get_file_directory(self):
        directory = utils.get_file_directory()
        self.assertIsInstance(directory, str)
        self.assertTrue(os.path.exists(directory))

    def test_get_temp_directory(self):
        self.assertTrue(os.path.exists(utils.get_temp_directory()))

    def test_get_themes_directory(self):
        themes = [
            "aquativo",
            "black",
            "blue",
            "clearlooks",
            "elegance",
            "keramik",
            "kroc",
            "plastik",
            "radiance",
            "winxpblue",
        ]
        folders = os.listdir(utils.get_themes_directory())
        for theme in themes:
            self.assertTrue(theme in folders)