fix: fix some error
This commit is contained in:
parent
4a55822a8f
commit
4f5c67b32e
@ -1,5 +1,5 @@
|
||||
from typing import Tuple
|
||||
from git import Repo
|
||||
from git import Repo # type: ignore
|
||||
import random
|
||||
from pathlib import Path
|
||||
|
||||
@ -44,7 +44,7 @@ def inject_random_backdoor(
|
||||
injected_python_files.append(python_file)
|
||||
injectedNum = len(injected_python_files)
|
||||
for python_file in injected_python_files:
|
||||
with open(python_file, "r+",errors="ignore") as f:
|
||||
with open(python_file, "r+", errors="ignore") as f:
|
||||
lines = f.readlines()
|
||||
total_lines = len(lines)
|
||||
inject_line_number = random.randint(0, total_lines)
|
||||
|
@ -1,9 +1,8 @@
|
||||
import unittest
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from detection.utils import read_file_content
|
||||
from .final_tests_util import *
|
||||
from .final_tests_util import clone_repo, Path, inject_random_backdoor
|
||||
from detection.Regexdetection import find_dangerous_functions
|
||||
from detection.GPTdetection import detectGPT
|
||||
|
||||
@ -27,7 +26,11 @@ class TestFinalTests(unittest.TestCase):
|
||||
for file in self.all_python_files:
|
||||
content = read_file_content(str(file))
|
||||
results = find_dangerous_functions(content, ".py")
|
||||
if len(results["high"]) > 0 or len(results["medium"]) > 0 or len(results["low"]) > 0:
|
||||
if (
|
||||
len(results["high"]) > 0
|
||||
or len(results["medium"]) > 0
|
||||
or len(results["low"]) > 0
|
||||
):
|
||||
detectedNum += 1
|
||||
possibly_dangerous_file.append(file)
|
||||
print(detectedNum / self.filesNum)
|
||||
@ -39,14 +42,17 @@ class TestFinalTests(unittest.TestCase):
|
||||
results = {}
|
||||
try:
|
||||
results = detectGPT(content)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
if len(results["high"]) > 0 or len(results["medium"]) > 0 or len(results["low"]) > 0:
|
||||
if (
|
||||
len(results["high"]) > 0
|
||||
or len(results["medium"]) > 0
|
||||
or len(results["low"]) > 0
|
||||
):
|
||||
GPTdetectedNum += 1
|
||||
print(GPTdetectedNum)
|
||||
self.assertGreaterEqual(GPTdetectedNum, detectedNum)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user