|
|
@@ -27,6 +27,8 @@ import tempfile |
|
|
|
|
|
|
|
|
from mindinsight.datavisual.data_transform.summary_watcher import SummaryWatcher |
|
|
from mindinsight.datavisual.data_transform.summary_watcher import SummaryWatcher |
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_directories_and_files(summary_base_dir, file_count, directory_count): |
|
|
def gen_directories_and_files(summary_base_dir, file_count, directory_count): |
|
|
"""Generate directories and files for test.""" |
|
|
"""Generate directories and files for test.""" |
|
|
@@ -52,12 +54,36 @@ def gen_directories_and_files(summary_base_dir, file_count, directory_count): |
|
|
shutil.copytree(os.path.join(summary_base_dir, 'run'), os.path.join(summary_base_dir, f'run{index}')) |
|
|
shutil.copytree(os.path.join(summary_base_dir, 'run'), os.path.join(summary_base_dir, f'run{index}')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_explain_directories_and_files(summary_base_dir, relative_path): |
|
|
|
|
|
"""Generate XAI directories and files.""" |
|
|
|
|
|
end_time = datetime.datetime.now() |
|
|
|
|
|
start_time = end_time - datetime.timedelta(days=10) |
|
|
|
|
|
start_ts = int(start_time.timestamp()) |
|
|
|
|
|
end_ts = int(end_time.timestamp()) |
|
|
|
|
|
os.mkdir(os.path.join(summary_base_dir, relative_path)) |
|
|
|
|
|
summary = os.path.join(summary_base_dir, |
|
|
|
|
|
relative_path, |
|
|
|
|
|
f'prefix.summary.{random.randint(start_ts, end_ts)}._explain') |
|
|
|
|
|
with open(summary, 'w'): |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSummaryWatcher: |
|
|
class TestSummaryWatcher: |
|
|
"""Test summary watcher.""" |
|
|
"""Test summary watcher.""" |
|
|
|
|
|
base_dir = '' |
|
|
|
|
|
|
|
|
|
|
|
def setup_class(self): |
|
|
|
|
|
"""Mock common environment for graph unittest.""" |
|
|
|
|
|
self.base_dir = tempfile.mkdtemp() |
|
|
|
|
|
|
|
|
|
|
|
def teardown_class(self): |
|
|
|
|
|
"""Delete temp files.""" |
|
|
|
|
|
if os.path.exists(self.base_dir): |
|
|
|
|
|
shutil.rmtree(self.base_dir) |
|
|
|
|
|
|
|
|
def test_list_summary_directories_with_overall_on(self): |
|
|
def test_list_summary_directories_with_overall_on(self): |
|
|
"""Test list_summary_directories method success.""" |
|
|
"""Test list_summary_directories method success.""" |
|
|
summary_base_dir = tempfile.mkdtemp() |
|
|
|
|
|
|
|
|
summary_base_dir = tempfile.mkdtemp(dir=self.base_dir) |
|
|
file_count = 10 |
|
|
file_count = 10 |
|
|
directory_count = 10 |
|
|
directory_count = 10 |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
@@ -70,7 +96,7 @@ class TestSummaryWatcher: |
|
|
|
|
|
|
|
|
def test_list_summary_directories_by_pagination(self): |
|
|
def test_list_summary_directories_by_pagination(self): |
|
|
"""Test list_summary_directories method success.""" |
|
|
"""Test list_summary_directories method success.""" |
|
|
summary_base_dir = tempfile.mkdtemp() |
|
|
|
|
|
|
|
|
summary_base_dir = tempfile.mkdtemp(dir=self.base_dir) |
|
|
file_count = 10 |
|
|
file_count = 10 |
|
|
directory_count = 10 |
|
|
directory_count = 10 |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
@@ -90,7 +116,7 @@ class TestSummaryWatcher: |
|
|
|
|
|
|
|
|
def test_is_summary_directory(self): |
|
|
def test_is_summary_directory(self): |
|
|
"""Test is_summary_directory method success.""" |
|
|
"""Test is_summary_directory method success.""" |
|
|
summary_base_dir = tempfile.mkdtemp() |
|
|
|
|
|
|
|
|
summary_base_dir = tempfile.mkdtemp(dir=self.base_dir) |
|
|
file_count = 1 |
|
|
file_count = 1 |
|
|
directory_count = 1 |
|
|
directory_count = 1 |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
@@ -104,7 +130,7 @@ class TestSummaryWatcher: |
|
|
|
|
|
|
|
|
def test_list_summaries(self): |
|
|
def test_list_summaries(self): |
|
|
"""Test list_summaries method success.""" |
|
|
"""Test list_summaries method success.""" |
|
|
summary_base_dir = tempfile.mkdtemp() |
|
|
|
|
|
|
|
|
summary_base_dir = tempfile.mkdtemp(dir=self.base_dir) |
|
|
file_count = 10 |
|
|
file_count = 10 |
|
|
directory_count = 1 |
|
|
directory_count = 1 |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
gen_directories_and_files(summary_base_dir, file_count, directory_count) |
|
|
@@ -115,3 +141,30 @@ class TestSummaryWatcher: |
|
|
summaries = summary_watcher.list_summaries(summary_base_dir, './\x00') |
|
|
summaries = summary_watcher.list_summaries(summary_base_dir, './\x00') |
|
|
assert not summaries |
|
|
assert not summaries |
|
|
shutil.rmtree(summary_base_dir) |
|
|
shutil.rmtree(summary_base_dir) |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("job_count", [0, 1, 3]) |
|
|
|
|
|
def test_list_explain_directories_only_base_dir(self, job_count): |
|
|
|
|
|
"""Test list explain directories with summary base dir, and no test offset and limit.""" |
|
|
|
|
|
summary_base_dir = tempfile.mkdtemp(dir=self.base_dir) |
|
|
|
|
|
if job_count: |
|
|
|
|
|
for i in range(job_count): |
|
|
|
|
|
gen_explain_directories_and_files(summary_base_dir, f'run{i}') |
|
|
|
|
|
summary_watcher = SummaryWatcher() |
|
|
|
|
|
total, _ = summary_watcher.list_explain_directories(summary_base_dir) |
|
|
|
|
|
assert total == job_count |
|
|
|
|
|
shutil.rmtree(summary_base_dir) |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("offset, limit", [(1, 1), (2, 2), (3, 3)]) |
|
|
|
|
|
def test_list_explain_dir_with_offset_limit(self, offset, limit): |
|
|
|
|
|
"""Test list explain dir with offset and limit.""" |
|
|
|
|
|
summary_base_dir = tempfile.mkdtemp(dir=self.base_dir) |
|
|
|
|
|
gen_directories_and_files(summary_base_dir, file_count=1, directory_count=3) |
|
|
|
|
|
for i in range(10): |
|
|
|
|
|
gen_explain_directories_and_files(summary_base_dir, f'run_{i}') |
|
|
|
|
|
|
|
|
|
|
|
summary_watcher = SummaryWatcher() |
|
|
|
|
|
_, result = summary_watcher.list_explain_directories(summary_base_dir, offset, limit) |
|
|
|
|
|
if offset == 3: |
|
|
|
|
|
assert len(result) == 1 |
|
|
|
|
|
else: |
|
|
|
|
|
assert len(result) == limit |