Add test configuration and parser/language detector tests
This commit is contained in:
93
tests/conftest.py
Normal file
93
tests/conftest.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""Pytest configuration and fixtures for gdiffer tests."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent / 'src'))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_diff():
|
||||
return """diff --git a/src/main.py b/src/main.py
|
||||
index 1234567..89abcde 100644
|
||||
--- a/src/main.py
|
||||
+++ b/src/main.py
|
||||
@@ -1,10 +1,12 @@
|
||||
+import os
|
||||
+import sys
|
||||
def main():
|
||||
- print("Hello")
|
||||
+ print("Hello, World!")
|
||||
for i in range(10):
|
||||
print(i)
|
||||
+ return 0
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def multi_file_diff():
|
||||
return """diff --git a/app.py b/app.py
|
||||
new file mode 100644
|
||||
index 0000000..1234567
|
||||
--- /dev/null
|
||||
+++ b/app.py
|
||||
@@ -0,0 +1,5 @@
|
||||
+def app():
|
||||
+ return "Hello"
|
||||
+
|
||||
diff --git a/lib.py b/lib.py
|
||||
deleted file mode 100644
|
||||
index 789abc..def123
|
||||
--- a/lib.py
|
||||
+++ /dev/null
|
||||
@@ -1,5 +0,0 @@
|
||||
-def lib():
|
||||
- return "World"
|
||||
-
|
||||
diff --git a/utils.py b/utils.py
|
||||
index abc123..xyz789 100644
|
||||
--- a/utils.py
|
||||
+++ b/utils.py
|
||||
@@ -1,3 +1,5 @@
|
||||
+import os
|
||||
def helper():
|
||||
return True
|
||||
+
|
||||
+def new_func(): pass
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sql_injection_diff():
|
||||
return """diff --git a/db.py b/db.py
|
||||
@@ -10,5 +10,6 @@ def get_user(username):
|
||||
query = "SELECT * FROM users WHERE name = '" + username + "'"
|
||||
return execute_query(query)
|
||||
+ query = "SELECT * FROM users WHERE id = " + user_id
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def diff_parser():
|
||||
from gdiffer.parser import DiffParser
|
||||
return DiffParser()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def language_detector():
|
||||
from gdiffer.language_detector import LanguageDetector
|
||||
return LanguageDetector()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def code_analyzer():
|
||||
from gdiffer.code_analyzer import CodeAnalyzer
|
||||
return CodeAnalyzer()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def issue_detector():
|
||||
from gdiffer.issue_detector import IssueDetector
|
||||
return IssueDetector()
|
||||
Reference in New Issue
Block a user