From 44a06190bbb1b412f0ed16a76b0a4aeef80975b7 Mon Sep 17 00:00:00 2001 From: Grant Lanham Date: Mon, 23 Sep 2024 23:37:30 -0400 Subject: [refactor] unit tests to utilize paramaterized and break down monolithic 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. --- tests/unit/test_search.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests/unit/test_search.py') diff --git a/tests/unit/test_search.py b/tests/unit/test_search.py index a60089aef..be95fb08e 100644 --- a/tests/unit/test_search.py +++ b/tests/unit/test_search.py @@ -110,7 +110,7 @@ class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring search.search() self.assertEqual(search.actual_timeout, 10.0) - def test_external_bang(self): + def test_external_bang_valid(self): search_query = SearchQuery( 'yes yes', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], @@ -124,8 +124,9 @@ class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring search = searx.search.Search(search_query) results = search.search() # For checking if the user redirected with the youtube external bang - self.assertTrue(results.redirect_url is not None) + self.assertIsNotNone(results.redirect_url) + def test_external_bang_none(self): search_query = SearchQuery( 'youtube never gonna give you up', [EngineRef(PUBLIC_ENGINE_NAME, 'general')], @@ -140,4 +141,4 @@ class SearchTestCase(SearxTestCase): # pylint: disable=missing-class-docstring with self.app.test_request_context('/search'): results = search.search() # This should not redirect - self.assertTrue(results.redirect_url is None) + self.assertIsNone(results.redirect_url) -- cgit v1.2.3