コード例 #1
0
    def test_no_uid(self):
        warning = mock.MagicMock()
        limiter = Limiter("my_check", "names", 10, warning_func=warning)
        for _ in range(0, 10):
            assert limiter.is_reached() is False
        assert limiter.get_status() == (10, 10, False)

        # Reach limit
        assert limiter.is_reached() is True
        assert limiter.get_status() == (11, 10, True)

        # Make sure warning is only sent once
        assert limiter.is_reached() is True
        warning.assert_called_once_with(
            "Check %s exceeded limit of %s %s, ignoring next ones", "my_check",
            10, "names")
コード例 #2
0
    def test_no_uid(self):
        warnings = []
        limiter = Limiter("my_check",
                          "names",
                          10,
                          warning_func=warnings.append)
        for _ in range(0, 10):
            assert limiter.is_reached() is False
        assert limiter.get_status() == (10, 10, False)

        # Reach limit
        assert limiter.is_reached() is True
        assert limiter.get_status() == (11, 10, True)
        assert warnings == [
            "Check my_check exceeded limit of 10 names, ignoring next ones"
        ]

        # Make sure warning is only sent once
        assert limiter.is_reached() is True
        assert len(warnings) == 1