Пример #1
0
    def test_app_context_bad_end(self):
        """Test with bad [end] property."""
        with self.assertRaisesRegex(
                TypeError,
                r"is not an \[int\]"):
            app_config = ag.AppConfig(logging.getLogger(), False)
            test_args = {
                "start": 2,
                "limit": 2,
                "timer": True,
                "operator": "+"
            }

            ac.AppContext(app_config, **test_args)
Пример #2
0
    def test_contructor(self):
        """Test the constructor of AppConfig class."""
        with self.assertRaises(
                BadArgumentError,
                msg="1. The class must raise an [BadArgumentError] exception"):
            py_ac.AppConfig(None)

        app_config = py_ac.AppConfig(logging.getLogger())
        self.assertFalse(app_config.log_enabled,
                         msg="2. The property [log_enabled] must be set")

        self.assertIsNotNone(app_config.logger,
                             msg="3. The [logger] property must be set")

        self.assertFalse(app_config.clear_onstart,
                         msg="4. The [clear_onstart] property must be set")

        with self.assertRaisesRegex(
                TypeError, r"\[bool\] type expected: \[<class 'str'>\] given"):
            py_ac.AppConfig(logging.getLogger(), log_enabled="false")

        with self.assertRaisesRegex(
                TypeError, r"\[bool\] type expected: \[<class 'str'>\] given"):
            py_ac.AppConfig(logging.getLogger(), clear_onstart="false")
Пример #3
0
    def test_app_context_bad_options(self):
        """Test with bad [options] property."""
        with self.assertRaisesRegex(
                TypeError,
                r"is not an instance of \[dict\]"):
            app_config = ag.AppConfig(logging.getLogger(), False)
            test_args = {
                "start": 1,
                "end": 2,
                "limit": 2,
                "timer": True,
                "operator": "+"
            }

            app_context = ac.AppContext(app_config, **test_args)
            app_context.options = False
Пример #4
0
    def test_app_context_singleton(self):
        """Test the singleton creation of AppContext class."""

        app_config = ag.AppConfig(logging.getLogger(), False)
        test_args = {
            "start": 1,
            "end": 2,
            "limit": 2,
            "timer": True,
            "operator": "+"
        }

        app_context = ac.AppContext(app_config, **test_args)
        self.assertIs(app_config, app_context.app_config,
                      msg="1. app_config property musts be ok")

        self.assertIs(1, app_context.start,
                      msg="2. start property musts be ok")

        self.assertIs(2, app_context.end,
                      msg="3. end property musts be ok")

        self.assertIs(2, app_context.limit,
                      msg="4. limit property musts be ok")

        self.assertIn("timer", app_context.options,
                      msg="5.1 options property musts contain timer key.")
        self.assertTrue(app_context.options.get("timer"),
                        msg="5.2 The timer option musts be set to [True]")

        self.assertIn("operator", app_context.options,
                      msg="6.1 options property musts contain operator key.")
        self.assertIs("+", app_context.options.get("operator"),
                      msg="6.2 The operator musts be set to [+] string")

        self.assertEqual(2, len(app_context.options),
                         msg="7. 2 items musts remain in [options] property.")

        self.assertIs(app_context, ac.AppContext(),
                      msg="8. The instance musts be a singleton")
Пример #5
0
 def test_log_enabled_setter(self):
     with self.assertRaisesRegex(
             TypeError, r"\[bool\] type expected: \[<class 'int'>\] given"):
         app_config = py_ac.AppConfig(logging.getLogger())
         app_config.log_enabled = 1
Пример #6
0
 def test_logger_setter(self):
     with self.assertRaises(BadArgumentError):
         app_config = py_ac.AppConfig(logging.getLogger())
         app_config.logger = None