From c158869096636154ddecfca4abc73c98f454e105 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Fri, 26 Jan 2018 18:10:39 -0330 Subject: [PATCH] Rename tools/lib/api_tests.py to zerver/lib/api_test_helpers.py. Now that the Markdown extension defined in zerver/lib/bugdown/api_generate_examples depended on code in the tools/lib/* directory, it caused the production tests to fail since the tools/ directory wouldn't exist in a production environment. --- tools/test-api | 2 +- tools/test-backend | 1 + .../lib/api_tests.py => zerver/lib/api_test_helpers.py | 0 zerver/lib/bugdown/api_code_examples.py | 10 +++------- 4 files changed, 5 insertions(+), 8 deletions(-) rename tools/lib/api_tests.py => zerver/lib/api_test_helpers.py (100%) diff --git a/tools/test-api b/tools/test-api index f6e8876e47..68a4f1ee99 100755 --- a/tools/test-api +++ b/tools/test-api @@ -14,7 +14,7 @@ os.chdir(ZULIP_PATH) from zulip import Client from tools.lib.test_server import test_server_running -from tools.lib.api_tests import test_the_api +from zerver.lib.api_test_helpers import test_the_api os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' django.setup() diff --git a/tools/test-backend b/tools/test-backend index e82ef77e21..661b80c1ea 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -107,6 +107,7 @@ not_yet_fully_covered = { 'zerver/lib/statistics.py', 'zerver/lib/test_fixtures.py', 'zerver/lib/test_runner.py', + 'zerver/lib/api_test_helpers.py', # Webhook integrations with incomplete coverage 'zerver/webhooks/basecamp/view.py', 'zerver/webhooks/beanstalk/view.py', diff --git a/tools/lib/api_tests.py b/zerver/lib/api_test_helpers.py similarity index 100% rename from tools/lib/api_tests.py rename to zerver/lib/api_test_helpers.py diff --git a/zerver/lib/bugdown/api_code_examples.py b/zerver/lib/bugdown/api_code_examples.py index 4d0989454c..8c04be43d6 100644 --- a/zerver/lib/bugdown/api_code_examples.py +++ b/zerver/lib/bugdown/api_code_examples.py @@ -9,11 +9,7 @@ from markdown.preprocessors import Preprocessor from typing import Any, Dict, Optional, List import markdown -ZULIP_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) -TOOLS_DIR = os.path.join(ZULIP_DIR, 'tools', 'lib') -sys.path.insert(0, TOOLS_DIR) - -import api_tests +import zerver.lib.api_test_helpers REGEXP = re.compile(r'\{generate_code_example\|\s*(.+?)\s*\|\s*(.+?)\s*\}') @@ -72,7 +68,7 @@ class APICodeExamplesPreprocessor(Preprocessor): def render_fixture(self, function: str) -> List[str]: fixture = [] - fixture_dict = api_tests.FIXTURES[function] + fixture_dict = zerver.lib.api_test_helpers.FIXTURES[function] fixture_json = ujson.dumps(fixture_dict, indent=4, sort_keys=True) fixture.append('```') @@ -82,7 +78,7 @@ class APICodeExamplesPreprocessor(Preprocessor): return fixture def render_code_example(self, function: str) -> List[str]: - method = api_tests.TEST_FUNCTIONS[function] + method = zerver.lib.api_test_helpers.TEST_FUNCTIONS[function] function_source_lines = inspect.getsourcelines(method)[0] ce_regex = re.compile(r'\# \{code_example\|\s*(.+?)\s*\}')