Further fix django folder structure so pytest also works

This commit is contained in:
afik.cohen 2024-05-31 20:01:51 -07:00
parent 1ff663ec51
commit ab43a26dc7
17 changed files with 33 additions and 18 deletions

View file

@ -5,7 +5,7 @@
<configuration>
<option name="rootFolder" value="$MODULE_DIR$/django/aiservice" />
<option name="settingsModule" value="aiservice/settings.py" />
<option name="manageScript" value="aiservice/manage.py" />
<option name="manageScript" value="manage.py" />
<option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" />
<option name="trackFilePattern" value="" />

View file

@ -6,7 +6,7 @@
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
<env name="DJANGO_SETTINGS_MODULE" value="settings" />
<env name="DJANGO_SETTINGS_MODULE" value="aiservice.settings" />
</envs>
<option name="SDK_HOME" value="$USER_HOME$/mambaforge/envs/aiservice/bin/python" />
<option name="SDK_NAME" value="$USER_HOME$/miniforge3/envs/aiservice" />

View file

@ -1 +0,0 @@
# required for the django test collector to find tests in tests/

View file

@ -10,6 +10,6 @@ import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "aiservice.settings")
application = get_asgi_application()

View file

@ -64,7 +64,7 @@ MIDDLEWARE: list[str] = [
"aiservice.middleware.healthcheck.HealthCheckMiddleware",
]
ROOT_URLCONF: str = "urls"
ROOT_URLCONF: str = "aiservice.urls"
TEMPLATES: list[str] = []

View file

@ -18,14 +18,12 @@ Including another URLconf
"""
# from django.contrib import admin
# from django.contrib import admin
from django.urls import path
from log_features.log_features import features_api
from optimizer.optimizer import optimize_api
from testgen.testgen import testgen_api
from django.urls import path
urlpatterns = [
path("ai/optimize", optimize_api.urls),
path("ai/testgen", testgen_api.urls),

View file

@ -10,6 +10,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "aiservice.settings")
application = get_wsgi_application()

View file

@ -11,7 +11,7 @@ from aiservice.env_specific import load_env, set_logging_level
def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "aiservice.settings")
# Get the network name of the machine
machine_id = platform.node()
try:

View file

@ -31,6 +31,7 @@ gitpython = "^3.1.43"
ruff = "^0.4.6"
ruff-lsp = "^0.0.53"
returns = "^0.22.0"
pytest-django = "^4.8.0"
[tool.poetry.group.dev]
optional = true

View file

@ -0,0 +1,2 @@
[pytest]
DJANGO_SETTINGS_MODULE = aiservice.settings

View file

@ -2,6 +2,7 @@ import ast
import os
from aiservice.models.functions_to_optimize import FunctionParent, FunctionToOptimize
from testgen.instrumentation.instrument_new_tests import InjectPerfAndLogging
os.environ["CODEFLASH_API_KEY"] = "cf-test-key"
@ -21,7 +22,9 @@ def test_InjectPerfAndLogging_with():
parents=[FunctionParent(name="HDBSCAN", type="ClassDef")],
)
new_module_node = InjectPerfAndLogging(
function_to_optimize, auxillary_functions, test_module_path,
function_to_optimize,
auxillary_functions,
test_module_path,
).visit(module_node)
expected = """def test_relative_validity_no_tree():
@ -47,7 +50,9 @@ def test_InjectPerfAndLogging():
parents=[FunctionParent(name="HDBSCAN", type="ClassDef")],
)
new_module_node = InjectPerfAndLogging(
function_to_optimize, auxillary_functions, test_module_path,
function_to_optimize,
auxillary_functions,
test_module_path,
).visit(module_node)
expected = """def test_relative_validity_no_tree():
hdbscan = HDBSCAN()
@ -73,7 +78,9 @@ def test_remove_bad_assert():
parents=[FunctionParent(name="HDBSCAN", type="ClassDef")],
)
new_module_node = InjectPerfAndLogging(
function_to_optimize, auxillary_functions, test_module_path,
function_to_optimize,
auxillary_functions,
test_module_path,
).visit(module_node)
expected = """def test_relative_validity_no_tree():
hdbscan = HDBSCAN()
@ -91,13 +98,17 @@ def test_translate_word_starting_with_single_consonant():
assert translate('banana') == 'ananabay'"""
function_to_optimize = FunctionToOptimize(
function_name="translate", file_path="/tmp/path", parents=[],
function_name="translate",
file_path="/tmp/path",
parents=[],
)
auxillary_functions = []
module_node = ast.parse(code)
test_module_path = "code_to_optimize_path"
new_module_node = InjectPerfAndLogging(
function_to_optimize, auxillary_functions, test_module_path,
function_to_optimize,
auxillary_functions,
test_module_path,
).visit(module_node)
expected = """def test_translate_word_starting_with_vowel():
_call__bound__arguments = inspect.signature(translate).bind('apple')
@ -283,9 +294,13 @@ if __name__ == '__main__':
module_node = ast.parse(code)
test_module_path = "code_to_optimize_path"
function_to_optimize = FunctionToOptimize(
function_name="sorter", file_path="/tmp/path", parents=[],
function_name="sorter",
file_path="/tmp/path",
parents=[],
)
new_module_node = InjectPerfAndLogging(
function_to_optimize, auxillary_functions, test_module_path,
function_to_optimize,
auxillary_functions,
test_module_path,
).visit(module_node)
assert ast.unparse(new_module_node).strip("\n") == expected