Skip to content

Commit

Permalink
Mock CoverageReport._extract_feature_option_mapping in unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
danjujan committed Aug 2, 2023
1 parent b89b05b commit 66be7da
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
6 changes: 4 additions & 2 deletions tests/data/test_llvm_coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections import defaultdict
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch

from plumbum import colors, local

Expand Down Expand Up @@ -407,8 +408,9 @@ def test_cov_show(self):
).replace("\x1b[41m\x1b[0m", "")
self.assertEqual(cov_show_slow_color_txt, output)

@unittest.skipIf(
not module_exists("vara_feature"), "vara_feature module not installed"
@patch(
"varats.data.reports.llvm_coverage_report.CoverageReport._extract_feature_option_mapping",
lambda self, xml: None
)
@run_in_test_environment(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
Expand Down
39 changes: 22 additions & 17 deletions tests/plots/test_llvm_coverage_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing as tp
import unittest
from unittest.mock import create_autospec
from unittest.mock import create_autospec, patch

from tests.helper_utils import run_in_test_environment, UnitTestFixtures
from varats.data.reports.llvm_coverage_report import (
Expand Down Expand Up @@ -290,9 +290,6 @@ def confusion_matrix(
self.assertEqual(confusion_matrix(region, 1.0).TN, 1)
self.assertEqual(confusion_matrix(region, 0.0).TN, 1)

@unittest.skipIf(
not module_exists("vara_feature"), "vara_feature module not installed"
)
@run_in_test_environment(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
)
Expand All @@ -303,9 +300,13 @@ def test_feature_report_interactions(self):
"FeaturePerfCSCollection", commit_hash.to_short_commit_hash()
) as base_dir:

reports = setup_reports(
"test_coverage_SimpleFeatureInteraction", base_dir
)
with patch(
"varats.data.reports.llvm_coverage_report.CoverageReport._extract_feature_option_mapping",
lambda self, xml: None
):
reports = setup_reports(
"test_coverage_SimpleFeatureInteraction", base_dir
)
report = reports.feature_report()

code_region = report.tree["src/SimpleFeatureInteraction/SFImain.cpp"
Expand Down Expand Up @@ -340,9 +341,6 @@ def test_feature_report_interactions(self):
pass
self.assertIn(region.coverage_features(), ["", "+True"])

@unittest.skipIf(
not module_exists("vara_feature"), "vara_feature module not installed"
)
@run_in_test_environment(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
)
Expand Down Expand Up @@ -522,9 +520,6 @@ def test_line_feature_plot(self):
)
)

@unittest.skipIf(
not module_exists("vara_feature"), "vara_feature module not installed"
)
@run_in_test_environment(
UnitTestFixtures.PAPER_CONFIGS, UnitTestFixtures.RESULT_FILES
)
Expand All @@ -534,10 +529,20 @@ def test_confusion_matrices(self):
with RepositoryAtCommit(
"FeaturePerfCSCollection", commit_hash.to_short_commit_hash()
) as base_dir:

reports = setup_reports(
"test_coverage_SimpleFeatureInteraction", base_dir
)
with patch(
"varats.data.reports.llvm_coverage_report.CoverageReport._extract_feature_option_mapping",
lambda self, xml: self.__setattr__(
"featue_option_mapping", {
"root": "",
"Compression": "--compress",
"Encryption": "--enc",
"Slow": "--slow"
}
)
):
reports = setup_reports(
"test_coverage_SimpleFeatureInteraction", base_dir
)
feature_option_mapping = reports.feature_option_mapping()
result_1 = reports.confusion_matrices(
feature_option_mapping, threshold=1.0
Expand Down
4 changes: 3 additions & 1 deletion varats/varats/data/reports/llvm_coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ def __contains__(self, element: CodeRegion) -> bool:
class FilenameRegionMapping(tp.Dict[str, CodeRegion]):
"""Mapping from function names to CodeRegion objects."""

def __init__(self, *args, base_dir: tp.Optional[Path] = None, **kwargs):
def __init__(

Check failure on line 507 in varats/varats/data/reports/llvm_coverage_report.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/data/reports/llvm_coverage_report.py#L507

error: Function is missing a type annotation for one or more arguments [no-untyped-def]
Raw output
varats/varats/data/reports/llvm_coverage_report.py:507:5: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
self, *args, base_dir: tp.Optional[Path] = None, **kwargs
) -> None:
self.base_dir = base_dir
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit 66be7da

Please sign in to comment.