File: test_resources.py

package info (click to toggle)
python-moderngl-window 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,096 kB
  • sloc: python: 12,076; makefile: 21
file content (72 lines) | stat: -rw-r--r-- 2,796 bytes parent folder | download
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pathlib import Path
from unittest import TestCase

from utils import settings_context

from moderngl_window import resources
from moderngl_window.conf import settings
from moderngl_window.exceptions import ImproperlyConfigured


class ResourcesTestCase(TestCase):
    relative_path = './resources'
    absolute_path = (Path(__file__).parent.resolve() / Path('fixtures/resources'))
    nonexist_path = (Path(__file__).parent.resolve() / 'resources')
    file_path = Path(__file__).resolve()

    settings = {
        'DATA_DIRS': [],
        'PROGRAM_DIRS': [],
        'TEXTURE_DIRS': [],
        'SCENE_DIRS': [],
    }

    def test_register_program_dir(self):
        """Register a program dir"""
        with settings_context(self.settings):
            resources.register_program_dir(self.absolute_path)
            self.assertEqual(len(settings.PROGRAM_DIRS), 1)

    def test_register_texture_dir(self):
        """Register a texture dir"""
        with settings_context(self.settings):
            resources.register_texture_dir(self.absolute_path)
            self.assertEqual(len(settings.TEXTURE_DIRS), 1)

    def test_register_scene_dir(self):
        """Register a scene dir"""
        with settings_context(self.settings):
            resources.register_scene_dir(self.absolute_path)
            self.assertEqual(len(settings.SCENE_DIRS), 1)

    def test_register_data_dir(self):
        """Register a data dir"""
        with settings_context(self.settings):
            resources.register_data_dir(self.absolute_path)
            self.assertEqual(len(settings.DATA_DIRS), 1)

    def test_relative_path(self):
        """Raise error if relative path is passed"""
        with settings_context(self.settings):
            with self.assertRaises(ImproperlyConfigured):
                resources.register_dir(self.relative_path)

    def test_non_dir(self):
        """Register nonexistent path"""
        with settings_context(self.settings):
            with self.assertRaises(ImproperlyConfigured):
                resources.register_dir(self.nonexist_path)

    def test_register_file(self):
        """Attempt to register a file as a search path"""
        with settings_context(self.settings):
            with self.assertRaises(ImproperlyConfigured):
                resources.register_dir(self.file_path)

    def test_reister_path_duplicates(self):
        """Ensure search path only occur once if registered multipel times"""
        with settings_context(self.settings):
            resources.register_dir(self.absolute_path)
            resources.register_dir(self.absolute_path)
            resources.register_dir(self.absolute_path)
            self.assertEqual(len(settings.DATA_DIRS), 1)