Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
Ref. #334
  • Loading branch information
treiher committed Jul 24, 2020
1 parent ef0d468 commit a13a1c3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test_python_optimized:
python3 -O -m pytest -n$(shell nproc) -vv -m "not hypothesis"

test_python_coverage:
python3 -m pytest -n$(shell nproc) -vv --cov=rflx --cov-branch --cov-fail-under=98.6 --cov-report=term-missing -m "not hypothesis" tests
python3 -m pytest -n$(shell nproc) -vv --cov=rflx --cov-branch --cov-fail-under=98.8 --cov-report=term-missing -m "not hypothesis" tests

test_spark: $(test-files)
gprbuild -P$(project)
Expand Down
8 changes: 0 additions & 8 deletions rflx/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ def __lt__(self, other: object) -> bool:
return self.start < other.start
return NotImplemented

def __hash__(self) -> int:
return hash(f"{self.__start}:{self.__source}:{self.__end}")

@property
def source(self) -> Optional[Path]:
return self.__source
Expand Down Expand Up @@ -87,11 +84,6 @@ class Severity(Enum):
WARNING = 3
ERROR = 4

def __gt__(self, other: "Severity") -> bool:
# ISSUE: PyCQA/pylint#2306
value = int(self.value)
return value > other.value

def __str__(self) -> str:
return str.lower(self.name)

Expand Down
2 changes: 1 addition & 1 deletion rflx/generator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ def length(field: Field, message: Message) -> Expr:
else:
if len(links) == 1:
length = links[0].length
elif len(links) > 1:
else:
length = If(
[(l.condition, l.length) for l in links],
Variable(const.TYPES_UNREACHABLE_BIT_LENGTH),
Expand Down
2 changes: 0 additions & 2 deletions rflx/generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,6 @@ def specification(field: Field) -> ProcedureSpecification:
def valid_message_condition(
message: Message, field: Field = INITIAL, structural: bool = False
) -> Expr:
if not message.outgoing(field):
return TRUE
return Or(
*[
l.condition
Expand Down
2 changes: 2 additions & 0 deletions rflx/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,8 @@ def invalid_relation(left: TypeExpr, right: TypeExpr) -> bool:
check_composite_element_range(relation, right, left)
elif isinstance(left, Enumeration) and isinstance(right, Enumeration):
check_enumeration(relation, left, right)
else:
assert False, f'unexpected relation type "{type(relation).__name__}"'

def __check_first_expression(self, link: Link, location: Location = None) -> None:
if link.first != UNDEFINED and not isinstance(link.first, First):
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pkg_resources
import pytest

import rflx.parser
from rflx import cli
from rflx.error import Location, Severity, Subsystem, fail

Expand Down Expand Up @@ -34,11 +35,16 @@ def test_main_check_parser_error() -> None:
assert "README.md:1:1: parser: error: " in str(cli.main(["rflx", "check", "README.md"]))


def test_main_check_model_error(monkeypatch: Any) -> None:
def test_main_check_model_error_parse(monkeypatch: Any) -> None:
monkeypatch.setattr(cli, "check", lambda x: raise_model_error())
assert "<stdin>:8:22: model: error: TEST" in str(cli.main(["rflx", "check", "README.md"]))


def test_main_check_model_error_create_model(monkeypatch: Any) -> None:
monkeypatch.setattr(rflx.parser.Parser, "create_model", lambda x: raise_model_error())
assert "<stdin>:8:22: model: error: TEST" in str(cli.main(["rflx", "check", "README.md"]))


def test_main_check_non_existent_file() -> None:
assert 'error: file not found: "non-existent file"' in str(
cli.main(["rflx", "check", "non-existent file"])
Expand Down

0 comments on commit a13a1c3

Please sign in to comment.