Skip to content

Commit d0ae72e

Browse files
drikusroorDrikus Roor
authored and
Drikus Roor
committed
refactor: Refactor imports to be compatible with unit tests
1 parent 3d5dba2 commit d0ae72e

12 files changed

+24
-15
lines changed

main.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from scripts.main import main

scripts/__init__.py

Whitespace-only changes.

scripts/browse.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import requests
22
from bs4 import BeautifulSoup
3-
from config import Config
4-
from llm_utils import create_chat_completion
3+
from .config import Config
4+
from .llm_utils import create_chat_completion
55

66
cfg = Config()
77

scripts/call_ai_function.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from config import Config
1+
from .config import Config
22

33
cfg = Config()
44

5-
from llm_utils import create_chat_completion
5+
from .llm_utils import create_chat_completion
66
# This is a magic function that can do anything with no-code. See
77
# https://github.com/Torantulino/AI-Functions for more info.
88
def call_ai_function(function, args, description, model=None):

scripts/json_parser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
22
from typing import Any, Dict, Union
3-
from call_ai_function import call_ai_function
4-
from config import Config
5-
from json_utils import correct_json
3+
from .call_ai_function import call_ai_function
4+
from .config import Config
5+
from .json_utils import correct_json
66

77
cfg = Config()
88

scripts/json_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
import json
3-
from config import Config
3+
from .config import Config
44

55
cfg = Config()
66

scripts/llm_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import openai
2-
from config import Config
2+
from .config import Config
33
cfg = Config()
44

55
openai.api_key = cfg.openai_api_key

tests.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import unittest
2+
3+
if __name__ == "__main__":
4+
# Load all tests from the 'scripts/tests' package
5+
suite = unittest.defaultTestLoader.discover('scripts/tests')
6+
7+
# Run the tests
8+
unittest.TextTestRunner().run(suite)

tests/__init__.py

Whitespace-only changes.

tests/context.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
import os
3+
sys.path.insert(0, os.path.abspath(
4+
os.path.join(os.path.dirname(__file__), '..')))

tests/test_browse_scrape_text.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Generated by CodiumAI
33

44
import requests
5-
import pytest
65

76
from scripts.browse import scrape_text
87

tests/json_tests.py tests/test_json_parser.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import unittest
2-
import os
3-
import sys
4-
# Probably a better way:
5-
sys.path.append(os.path.abspath('../scripts'))
6-
from json_parser import fix_and_parse_json
2+
3+
from scripts.json_parser import fix_and_parse_json
74

85
class TestParseJson(unittest.TestCase):
96
def test_valid_json(self):

0 commit comments

Comments
 (0)