Skip to content

Commit

Permalink
refactor: Refactor imports to be compatible with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor authored and Drikus Roor committed Apr 12, 2023
1 parent 3d5dba2 commit d0ae72e
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from scripts.main import main
Empty file added scripts/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions scripts/browse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
from bs4 import BeautifulSoup
from config import Config
from llm_utils import create_chat_completion
from .config import Config
from .llm_utils import create_chat_completion

cfg = Config()

Expand Down
4 changes: 2 additions & 2 deletions scripts/call_ai_function.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from config import Config
from .config import Config

cfg = Config()

from llm_utils import create_chat_completion
from .llm_utils import create_chat_completion
# This is a magic function that can do anything with no-code. See
# https://github.com/Torantulino/AI-Functions for more info.
def call_ai_function(function, args, description, model=None):
Expand Down
6 changes: 3 additions & 3 deletions scripts/json_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from typing import Any, Dict, Union
from call_ai_function import call_ai_function
from config import Config
from json_utils import correct_json
from .call_ai_function import call_ai_function
from .config import Config
from .json_utils import correct_json

cfg = Config()

Expand Down
2 changes: 1 addition & 1 deletion scripts/json_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import json
from config import Config
from .config import Config

cfg = Config()

Expand Down
2 changes: 1 addition & 1 deletion scripts/llm_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import openai
from config import Config
from .config import Config
cfg = Config()

openai.api_key = cfg.openai_api_key
Expand Down
8 changes: 8 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import unittest

if __name__ == "__main__":
# Load all tests from the 'scripts/tests' package
suite = unittest.defaultTestLoader.discover('scripts/tests')

# Run the tests
unittest.TextTestRunner().run(suite)
Empty file added tests/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions tests/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys
import os
sys.path.insert(0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')))
1 change: 0 additions & 1 deletion tests/test_browse_scrape_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Generated by CodiumAI

import requests
import pytest

from scripts.browse import scrape_text

Expand Down
7 changes: 2 additions & 5 deletions tests/json_tests.py → tests/test_json_parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import unittest
import os
import sys
# Probably a better way:
sys.path.append(os.path.abspath('../scripts'))
from json_parser import fix_and_parse_json

from scripts.json_parser import fix_and_parse_json

class TestParseJson(unittest.TestCase):
def test_valid_json(self):
Expand Down

0 comments on commit d0ae72e

Please sign in to comment.