Files
vibeguard/tests/fixtures/__init__.py
7000pctAUTO d2e83792ae
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
Add integration tests and fixtures
2026-02-03 07:03:23 +00:00

173 lines
3.2 KiB
Python

"""Test fixtures for VibeGuard."""
from pathlib import Path
class TestFixtures:
"""Test fixtures for VibeGuard tests."""
@staticmethod
def get_python_fixture(name: str) -> str:
"""Get a Python test fixture."""
fixtures = {
"magic_string": '''
MAGIC_VALUE = "this is a very long magic string that should be detected as an anti-pattern"
USER_ID = 12345
MAX_RETRIES = 5
def process_data(data):
return data
def calculate():
return 42
try:
result = 1 / 0
except:
pass
''',
"good_python": '''
MAGIC_VALUE = "short"
MAX_RETRIES = 5
def process_data(data: list) -> dict:
"""Process data and return result."""
return {}
def calculate() -> int:
"""Calculate and return value."""
return 42
try:
result = 1 / 0
except ZeroDivisionError:
pass
''',
"type_check": '''
value = "test"
if type(value) == str:
print("string")
''',
}
return fixtures.get(name, "")
@staticmethod
def get_javascript_fixture(name: str) -> str:
"""Get a JavaScript test fixture."""
fixtures = {
"console_log": '''
function calculate() {
console.log("Debug: calculation started");
return 42;
}
var oldStyle = "should use const";
''',
"good_javascript": '''
const calculate = () => {
return 42;
};
const ERROR_MESSAGES = {
NOT_FOUND: "Resource not found"
};
''',
"promise_wrapper": '''
const getValue = () => {
return new Promise((resolve) => {
resolve(42);
});
};
''',
}
return fixtures.get(name, "")
@staticmethod
def get_typescript_fixture(name: str) -> str:
"""Get a TypeScript test fixture."""
fixtures = {
"any_type": '''
interface userData {
id: number;
name: any;
}
const processData = (data: any) => {
return data;
};
''',
"good_typescript": '''
interface UserData {
id: number;
name: string;
}
const processData = (data: UserData): UserData => {
return data;
};
''',
}
return fixtures.get(name, "")
@staticmethod
def get_go_fixture(name: str) -> str:
"""Get a Go test fixture."""
fixtures = {
"ignored_error": '''
func example() {
_, err := someFunction()
_ = err
}
''',
"good_go": '''
func example() error {
_, err := someFunction()
return err
}
''',
"context_background": '''
func handler(w http.ResponseWriter, r *http.Request) {
ctx := context.Background()
// use ctx
}
''',
}
return fixtures.get(name, "")
@staticmethod
def get_rust_fixture(name: str) -> str:
"""Get a Rust test fixture."""
fixtures = {
"unnecessary_clone": '''
#[derive(Copy, Clone)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 1, y: 2 };
let q = p.clone();
}
''',
"good_rust": '''
#[derive(Copy, Clone)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let p = Point { x: 1, y: 2 };
let q = p;
}
''',
}
return fixtures.get(name, "")
@staticmethod
def write_fixture(path: Path, content: str) -> None:
"""Write a fixture file."""
path.write_text(content)