File: test_utils.py

package info (click to toggle)
python-moderngl-window 2.4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 69,260 kB
  • sloc: python: 11,225; makefile: 20
file content (25 lines) | stat: -rw-r--r-- 837 bytes parent folder | download | duplicates (2)
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
from unittest import TestCase

from moderngl_window.utils.module_loading import import_string


class UtilsTestCase(TestCase):

    def test_import_string(self):
        """Ensure importing a class returns a type"""
        cls = import_string('moderngl_window.context.headless.Window')
        self.assertEqual(type(cls), type)

    def test_import_error(self):
        """ImportError should be raised"""
        with self.assertRaises(ImportError):
            import_string('this.is.bs')

    def test_no_dotted_path(self):
        with self.assertRaises(ImportError):
            import_string('nonexistingmodule')

    def test_import_error_missing_cls(self):
        """ImportError when missin class in module"""
        with self.assertRaises(ImportError):
            import_string('moderngl_window.context.headless.NadaWindow')