2024-10-30 08:30:10 +00:00
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
2024-11-07 19:33:10 +00:00
|
|
|
|
from codeflash.code_utils.static_analysis import ImportedInternalModuleAnalysis, analyze_imported_modules
|
2024-10-30 08:30:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_analyze_imported_modules() -> None:
|
|
|
|
|
|
code_str = """
|
|
|
|
|
|
import os
|
|
|
|
|
|
import sys
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
from . import mymodule
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
from pandas import DataFrame
|
|
|
|
|
|
from pathlib import *
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2024-11-01 02:08:20 +00:00
|
|
|
|
from codeflash.code_utils.static_analysis import ImportedInternalModuleAnalysis
|
2024-10-30 08:30:10 +00:00
|
|
|
|
|
2024-11-01 02:08:20 +00:00
|
|
|
|
def a_function():
|
|
|
|
|
|
from codeflash.code_utils.static_analysis import analyze_imported_modules
|
2024-10-30 08:30:10 +00:00
|
|
|
|
from returns.result import Failure, Success
|
|
|
|
|
|
pass
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
module_file_path = Path(__file__)
|
|
|
|
|
|
project_root = (Path(__file__).parent.resolve() / "../").resolve()
|
|
|
|
|
|
|
|
|
|
|
|
expected_imported_module_analysis = [
|
2024-11-01 02:08:20 +00:00
|
|
|
|
ImportedInternalModuleAnalysis(
|
2024-10-30 08:30:10 +00:00
|
|
|
|
name="static_analysis",
|
|
|
|
|
|
full_name="codeflash.code_utils.static_analysis",
|
2024-11-01 02:08:20 +00:00
|
|
|
|
file_path=project_root / Path("codeflash/code_utils/static_analysis.py"),
|
2024-10-30 08:30:10 +00:00
|
|
|
|
),
|
2024-11-01 02:08:20 +00:00
|
|
|
|
ImportedInternalModuleAnalysis(
|
|
|
|
|
|
name="mymodule", full_name="tests.mymodule", file_path=project_root / Path("tests/mymodule.py")
|
2024-10-30 08:30:10 +00:00
|
|
|
|
),
|
|
|
|
|
|
]
|
2024-11-07 19:33:10 +00:00
|
|
|
|
actual_imported_module_analysis = analyze_imported_modules(code_str, module_file_path, project_root)
|
2024-10-30 08:30:10 +00:00
|
|
|
|
assert set(actual_imported_module_analysis) == set(expected_imported_module_analysis)
|