Update version info and tests

This commit is contained in:
2022-11-14 00:54:18 +01:00
parent 8d06a2c5f6
commit 5a3ae6f440
8 changed files with 81 additions and 17 deletions

View File

@@ -1 +0,0 @@
__version__ = "0.7.1"

View File

@@ -1 +1 @@
__version__ = "0.2.0"
__version__ = "0.3.0"

View File

@@ -5,6 +5,7 @@ from openpyxl import load_workbook
from .TestBase import TestBase
from ..Utils import Folders, Files, NO_RESULTS
from ..Results import Benchmark
from .._version import __version__
class BenchmarkTest(TestBase):
@@ -107,6 +108,16 @@ class BenchmarkTest(TestBase):
benchmark.excel()
file_name = benchmark.get_excel_file_name()
book = load_workbook(file_name)
replace = None
with_this = None
for sheet_name in book.sheetnames:
sheet = book[sheet_name]
self.check_excel_sheet(sheet, f"exreport_excel_{sheet_name}")
if sheet_name == "Datasets":
replace = self.benchmark_version
with_this = __version__
self.check_excel_sheet(
sheet,
f"exreport_excel_{sheet_name}",
replace=replace,
with_this=with_this,
)

View File

@@ -4,6 +4,7 @@ from unittest.mock import patch
from .TestBase import TestBase
from ..Results import Report, BaseReport, ReportBest, ReportDatasets
from ..Utils import Symbols
from .._version import __version__
class ReportTest(TestBase):
@@ -81,7 +82,7 @@ class ReportTest(TestBase):
output_text = stdout.getvalue().splitlines()
# Compare replacing STree version
for line, index in zip(expected, range(len(expected))):
if "1.2.4" in line:
if self.stree_version in line:
# replace STree version
line = self.replace_STree_version(line, output_text, index)
@@ -97,4 +98,12 @@ class ReportTest(TestBase):
def test_report_datasets(self, mock_output):
report = ReportDatasets()
report.report()
self.check_output_file(mock_output, "report_datasets")
file_name = f"report_datasets{self.ext}"
with open(os.path.join(self.test_files, file_name)) as f:
expected = f.read()
output_text = mock_output.getvalue().splitlines()
for line, index in zip(expected.splitlines(), range(len(expected))):
if self.benchmark_version in line:
# replace benchmark version
line = self.replace_benchmark_version(line, output_text, index)
self.assertEqual(line, output_text[index])

View File

@@ -15,6 +15,8 @@ class TestBase(unittest.TestCase):
self.test_files = "test_files"
self.output = "sys.stdout"
self.ext = ".test"
self.benchmark_version = "0.2.0"
self.stree_version = "1.2.4"
super().__init__(*args, **kwargs)
def remove_files(self, files, folder):
@@ -31,7 +33,9 @@ class TestBase(unittest.TestCase):
if value is not None:
print(f'{row};{col};"{value}"', file=f)
def check_excel_sheet(self, sheet, file_name):
def check_excel_sheet(
self, sheet, file_name, replace=None, with_this=None
):
file_name += self.ext
with open(os.path.join(self.test_files, file_name), "r") as f:
expected = csv.reader(f, delimiter=";")
@@ -43,6 +47,9 @@ class TestBase(unittest.TestCase):
value = float(value)
except ValueError:
pass
if replace is not None and isinstance(value, str):
if replace in value:
value = value.replace(replace, with_this)
self.assertEqual(sheet.cell(int(row), int(col)).value, value)
def check_output_file(self, output, file_name):
@@ -51,10 +58,15 @@ class TestBase(unittest.TestCase):
expected = f.read()
self.assertEqual(output.getvalue(), expected)
@staticmethod
def replace_STree_version(line, output, index):
idx = line.find("1.2.4")
return line.replace("1.2.4", output[index][idx : idx + 5])
def replace_STree_version(self, line, output, index):
idx = line.find(self.stree_version)
return line.replace(self.stree_version, output[index][idx : idx + 5])
def replace_benchmark_version(self, line, output, index):
idx = line.find(self.benchmark_version)
return line.replace(
self.benchmark_version, output[index][idx : idx + 5]
)
def check_file_file(self, computed_file, expected_file):
with open(computed_file) as f:

View File

@@ -2,6 +2,7 @@ import os
from openpyxl import load_workbook
from ...Utils import NO_RESULTS, Folders, Files
from ..TestBase import TestBase
from ..._version import __version__
class BeBenchmarkTest(TestBase):
@@ -43,9 +44,19 @@ class BeBenchmarkTest(TestBase):
Folders.exreport, Files.exreport_excel(self.score)
)
book = load_workbook(file_name)
replace = None
with_this = None
for sheet_name in book.sheetnames:
sheet = book[sheet_name]
self.check_excel_sheet(sheet, f"exreport_excel_{sheet_name}")
if sheet_name == "Datasets":
replace = self.benchmark_version
with_this = __version__
self.check_excel_sheet(
sheet,
f"exreport_excel_{sheet_name}",
replace=replace,
with_this=with_this,
)
def test_be_benchmark_single(self):
stdout, stderr = self.execute_script(

View File

@@ -2,6 +2,7 @@ import os
from openpyxl import load_workbook
from ...Utils import Folders, Files
from ..TestBase import TestBase
from ..._version import __version__
class BeReportTest(TestBase):
@@ -14,6 +15,7 @@ class BeReportTest(TestBase):
"results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.xlsx",
]
self.remove_files(files, Folders.results)
self.remove_files([Files.datasets_report_excel], os.getcwd())
return super().tearDown()
def test_be_report(self):
@@ -41,16 +43,37 @@ class BeReportTest(TestBase):
def test_be_report_datatsets(self):
stdout, stderr = self.execute_script("be_report", [])
self.assertEqual(stderr.getvalue(), "")
self.check_output_file(stdout, "report_datasets")
file_name = f"report_datasets{self.ext}"
with open(os.path.join(self.test_files, file_name)) as f:
expected = f.read()
output_text = stdout.getvalue().splitlines()
for line, index in zip(expected.splitlines(), range(len(expected))):
if self.benchmark_version in line:
# replace benchmark version
line = self.replace_benchmark_version(line, output_text, index)
self.assertEqual(line, output_text[index])
def test_be_report_datasets_excel(self):
stdout, stderr = self.execute_script("be_report", ["-x", "1"])
self.assertEqual(stderr.getvalue(), "")
self.check_output_file(stdout, "report_datasets")
file_name = f"report_datasets{self.ext}"
with open(os.path.join(self.test_files, file_name)) as f:
expected = f.read()
output_text = stdout.getvalue().splitlines()
for line, index in zip(expected.splitlines(), range(len(expected))):
if self.benchmark_version in line:
# replace benchmark version
line = self.replace_benchmark_version(line, output_text, index)
self.assertEqual(line, output_text[index])
file_name = os.path.join(os.getcwd(), Files.datasets_report_excel)
book = load_workbook(file_name)
sheet = book["Datasets"]
self.check_excel_sheet(sheet, "exreport_excel_Datasets")
self.check_excel_sheet(
sheet,
"exreport_excel_Datasets",
replace=self.benchmark_version,
with_this=__version__,
)
def test_be_report_best(self):
stdout, stderr = self.execute_script(

View File

@@ -49,15 +49,14 @@ setuptools.setup(
name="benchmark",
version=get_data("version", "_version.py"),
license=get_data("license"),
description="Oblique decision tree with svm nodes",
description="Benchmark of models with different datasets",
long_description=readme(),
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
url="https://github.com/Doctorado-ML/benchmark",
author=get_data("author"),
author_email=get_data("author_email"),
keywords="scikit-learn oblique-classifier oblique-decision-tree decision-\
tree svm svc",
keywords="scikit-learn benchmark",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: " + get_data("license"),