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