From 011087747894221d298a934659aa36c95a4bb651 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 27 Oct 2021 08:50:30 +0200 Subject: [PATCH] use Config object when testing config I don't see a reason to mock a simple object --- tests/test_configurer.py | 45 +++------------------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/tests/test_configurer.py b/tests/test_configurer.py index 538086124..d860069d0 100644 --- a/tests/test_configurer.py +++ b/tests/test_configurer.py @@ -3,53 +3,14 @@ """ from traitlets import Dict +from traitlets.config import Config import os import sys from tljh import configurer -class MockConfigurer: - """ - Mock a Traitlet Configurable object. - - Equivalent to the `c` in `c.JupyterHub.some_property` method of setting - traitlet properties. If an accessed attribute doesn't exist, a new instance - of EmtpyObject is returned. This lets us set arbitrary attributes two - levels deep. - - >>> c = MockConfigurer() - >>> c.FirstLevel.second_level = 'hi' - >>> c.FirstLevel.second_level == 'hi' - True - >>> hasattr(c.FirstLevel, 'does_not_exist') - False - """ - - class _EmptyObject: - """ - Empty class for putting attributes in. - """ - pass - - def __getattr__(self, k): - if k not in self.__dict__: - self.__dict__[k] = MockConfigurer._EmptyObject() - return self.__dict__[k] - - -def test_mock_configurer(): - """ - Test the MockConfigurer's mocking ability - """ - m = MockConfigurer() - m.SomethingSomething = 'hi' - m.FirstLevel.second_level = 'boo' - - assert m.SomethingSomething == 'hi' - assert m.FirstLevel.second_level == 'boo' - assert not hasattr(m.FirstLevel, 'non_existent') def apply_mock_config(overrides): @@ -58,7 +19,7 @@ def apply_mock_config(overrides): overrides should be a dict that matches what you parse from a config.yaml """ - c = MockConfigurer() + c = Config() configurer.apply_config(overrides, c) return c @@ -101,7 +62,7 @@ def test_app_default(): """ c = apply_mock_config({}) # default_url is not set, so JupyterHub will pick default. - assert not hasattr(c.Spawner, 'default_url') + assert 'default_url' not in c.Spawner def test_app_jupyterlab():