forked from searxng/searxng
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] unit tests to utilize paramaterized and break down monolit…
…hic tests - for tests which perform the same arrange/act/assert pattern but with different data, the data portion has been moved to the ``paramaterized.expand`` fields - for monolithic tests which performed multiple arrange/act/asserts, they have been broken up into different unit tests. - when possible, change generic assert statements to more concise asserts (i.e. ``assertIsNone``) This work ultimately is focused on creating smaller and more concise tests. While paramaterized may make adding new configurations for existing tests easier, that is just a beneficial side effect. The main benefit is that smaller tests are easier to reason about, meaning they are easier to debug when they start failing. This improves the developer experience in debugging what went wrong when refactoring the project. Total number of tests went from 192 -> 259; or, broke apart larger tests into 69 more concise ones.
- Loading branch information
1 parent
042c719
commit 44a0619
Showing
12 changed files
with
356 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
# pylint: disable=missing-module-docstring | ||
|
||
from parameterized import parameterized | ||
from tests import SearxTestCase | ||
import searx.exceptions | ||
from searx import get_setting | ||
|
||
|
||
class TestExceptions(SearxTestCase): # pylint: disable=missing-class-docstring | ||
def test_default_suspend_time(self): | ||
with self.assertRaises(searx.exceptions.SearxEngineAccessDeniedException) as e: | ||
raise searx.exceptions.SearxEngineAccessDeniedException() | ||
@parameterized.expand( | ||
[ | ||
searx.exceptions.SearxEngineAccessDeniedException, | ||
searx.exceptions.SearxEngineCaptchaException, | ||
searx.exceptions.SearxEngineTooManyRequestsException, | ||
] | ||
) | ||
def test_default_suspend_time(self, exception): | ||
with self.assertRaises(exception) as e: | ||
raise exception() | ||
self.assertEqual( | ||
e.exception.suspended_time, | ||
get_setting(searx.exceptions.SearxEngineAccessDeniedException.SUSPEND_TIME_SETTING), | ||
get_setting(exception.SUSPEND_TIME_SETTING), | ||
) | ||
|
||
with self.assertRaises(searx.exceptions.SearxEngineCaptchaException) as e: | ||
raise searx.exceptions.SearxEngineCaptchaException() | ||
self.assertEqual( | ||
e.exception.suspended_time, get_setting(searx.exceptions.SearxEngineCaptchaException.SUSPEND_TIME_SETTING) | ||
) | ||
|
||
with self.assertRaises(searx.exceptions.SearxEngineTooManyRequestsException) as e: | ||
raise searx.exceptions.SearxEngineTooManyRequestsException() | ||
self.assertEqual( | ||
e.exception.suspended_time, | ||
get_setting(searx.exceptions.SearxEngineTooManyRequestsException.SUSPEND_TIME_SETTING), | ||
) | ||
|
||
def test_custom_suspend_time(self): | ||
with self.assertRaises(searx.exceptions.SearxEngineAccessDeniedException) as e: | ||
raise searx.exceptions.SearxEngineAccessDeniedException(suspended_time=1337) | ||
@parameterized.expand( | ||
[ | ||
searx.exceptions.SearxEngineAccessDeniedException, | ||
searx.exceptions.SearxEngineCaptchaException, | ||
searx.exceptions.SearxEngineTooManyRequestsException, | ||
] | ||
) | ||
def test_custom_suspend_time(self, exception): | ||
with self.assertRaises(exception) as e: | ||
raise exception(suspended_time=1337) | ||
self.assertEqual(e.exception.suspended_time, 1337) | ||
|
||
with self.assertRaises(searx.exceptions.SearxEngineCaptchaException) as e: | ||
raise searx.exceptions.SearxEngineCaptchaException(suspended_time=1409) | ||
self.assertEqual(e.exception.suspended_time, 1409) | ||
|
||
with self.assertRaises(searx.exceptions.SearxEngineTooManyRequestsException) as e: | ||
raise searx.exceptions.SearxEngineTooManyRequestsException(suspended_time=1543) | ||
self.assertEqual(e.exception.suspended_time, 1543) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.