mirror of
https://github.com/Doctorado-ML/benchmark.git
synced 2025-08-15 15:35:52 +00:00
Update tests be_init_project_tests
This commit is contained in:
@@ -21,12 +21,10 @@ def main(args_test=None):
|
||||
os.makedirs(folder)
|
||||
except FileExistsError as e:
|
||||
print(e)
|
||||
try:
|
||||
env_src = os.path.join(Folders.src(), "..", f"{Files.dot_env}.dist")
|
||||
env_to = os.path.join(args.project_name, Files.dot_env)
|
||||
os.system(f"cp {env_src} {env_to}")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
exit(1)
|
||||
env_src = os.path.join(Folders.src(), "..", f"{Files.dot_env}.dist")
|
||||
env_to = os.path.join(args.project_name, Files.dot_env)
|
||||
os.system(f"cp {env_src} {env_to}")
|
||||
print("Done!")
|
||||
print(
|
||||
"Please, edit .env file with your settings and add a datasets folder"
|
||||
|
@@ -13,6 +13,7 @@ from .PairCheck_test import PairCheckTest
|
||||
from .Arguments_test import ArgumentsTest
|
||||
from .scripts.Be_Pair_check_test import BePairCheckTest
|
||||
from .scripts.Be_List_test import BeListTest
|
||||
from .scripts.Be_Init_Project_test import BeInitProjectTest
|
||||
from .scripts.Be_Report_test import BeReportTest
|
||||
from .scripts.Be_Summary_test import BeSummaryTest
|
||||
from .scripts.Be_Grid_test import BeGridTest
|
||||
|
66
benchmark/tests/scripts/Be_Init_Project_test.py
Normal file
66
benchmark/tests/scripts/Be_Init_Project_test.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
from ..TestBase import TestBase
|
||||
from ...Utils import Folders
|
||||
|
||||
|
||||
class BeInitProjectTest(TestBase):
|
||||
def setUp(self):
|
||||
self.prepare_scripts_env()
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists("test_project"):
|
||||
os.system("rm -rf test_project")
|
||||
|
||||
def assertIsFile(self, file_name):
|
||||
if not os.path.isfile(file_name):
|
||||
raise AssertionError(f"File {str(file_name)} does not exist")
|
||||
|
||||
def assertIsFolder(self, path):
|
||||
if not os.path.exists(path):
|
||||
raise AssertionError(f"Folder {str(path)} does not exist")
|
||||
|
||||
def test_be_init_project(self):
|
||||
test_project = "test_project"
|
||||
stdout, stderr = self.execute_script("be_init_project", [test_project])
|
||||
self.assertEqual(stderr.getvalue(), "")
|
||||
self.check_output_file(stdout, "be_init_project")
|
||||
# check folders
|
||||
expected = [
|
||||
Folders.results,
|
||||
Folders.hidden_results,
|
||||
Folders.exreport,
|
||||
Folders.report,
|
||||
Folders.img,
|
||||
]
|
||||
for folder in expected:
|
||||
self.assertIsFolder(os.path.join(test_project, folder))
|
||||
self.assertIsFile(os.path.join(test_project, ".env"))
|
||||
os.system(f"rm -rf {test_project}")
|
||||
|
||||
@patch("sys.stdout", new_callable=StringIO)
|
||||
@patch("sys.stderr", new_callable=StringIO)
|
||||
def test_be_init_project_no_arguments(self, stdout, stderr):
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
module = self.search_script("be_init_project")
|
||||
module.main("")
|
||||
self.assertEqual(cm.exception.code, 2)
|
||||
self.check_output_file(stdout, "be_init_project_no_arguments")
|
||||
self.assertEqual(stderr.getvalue(), "")
|
||||
|
||||
@patch("sys.stdout", new_callable=StringIO)
|
||||
@patch("sys.stderr", new_callable=StringIO)
|
||||
def test_be_init_project_twice(self, stdout, stderr):
|
||||
test_project = "test_project"
|
||||
self.execute_script("be_init_project", [test_project])
|
||||
with self.assertRaises(SystemExit) as cm:
|
||||
module = self.search_script("be_init_project")
|
||||
module.main([test_project])
|
||||
self.assertEqual(cm.exception.code, 1)
|
||||
self.assertEqual(
|
||||
stderr.getvalue(),
|
||||
f"Creating folder {test_project}\n"
|
||||
f"[Errno 17] File exists: '{test_project}'\n",
|
||||
)
|
||||
self.assertEqual(stdout.getvalue(), "")
|
10
benchmark/tests/test_files/be_init_project.test
Normal file
10
benchmark/tests/test_files/be_init_project.test
Normal file
@@ -0,0 +1,10 @@
|
||||
Creating folder test_project
|
||||
Creating folder test_project/results
|
||||
Creating folder test_project/hidden_results
|
||||
Creating folder test_project/exreport
|
||||
Creating folder test_project/exreport/exreport_output
|
||||
Creating folder test_project/img
|
||||
Done!
|
||||
Please, edit .env file with your settings and add a datasets folder
|
||||
with an all.txt file with the datasets you want to use.
|
||||
In that folder you have to include all the datasets you'll use.
|
@@ -0,0 +1,2 @@
|
||||
usage: be_init_project [-h] project_name
|
||||
be_init_project: error: the following arguments are required: project_name
|
Reference in New Issue
Block a user