Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/linters/.mypy.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[mypy]
python_version = 3.10
disallow_untyped_defs = True
disallow_untyped_defs = True

[mypy-pytest.*]
ignore_missing_imports = True

[mypy-matplotlib.*]
ignore_missing_imports = True
8 changes: 3 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on: # yamllint disable-line rule:truthy
permissions: { }

jobs:
build:
lint:
name: Lint
runs-on: ubuntu-latest

Expand All @@ -27,15 +27,13 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
# super-linter needs the full git history to get the
# list of files that changed across commits
fetch-depth: 0

- name: Super-linter
uses: super-linter/super-linter@v7.1.0 # x-release-please-version
uses: super-linter/super-linter@v7.1.0 # x-release-please-version
env:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_ALL_CODEBASE: false
VALIDATE_PYTHON_FLAKE8: true
VALIDATE_PYTHON_MYPY: true
VALIDATE_PYTHON_MYPY: true
6 changes: 3 additions & 3 deletions framalytics/FRAM_Visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _hex_to_color(self,
def _draw_function_nodes(self,
function_data: pd.DataFrame,
connection_data: pd.DataFrame,
ax: Axes):
ax: Axes) -> None:
"""
Draw FRAM functions onto a Matplotlib axes.

Expand Down Expand Up @@ -122,7 +122,7 @@ def _draw_function_nodes(self,
def _draw_aspects(self,
node_x_coords: pd.Series | list,
node_y_coords: pd.Series | list,
ax: Axes):
ax: Axes) -> None:
"""
Draw the six aspects around each function.

Expand Down Expand Up @@ -234,7 +234,7 @@ def _draw_bezier_curves(self,
connection_data: pd.DataFrame,
ax: Axes,
real_connections: dict | None = None,
appearance: str | None = None):
appearance: str | None = None) -> None:
"""
Draw connections between functions.

Expand Down
44 changes: 23 additions & 21 deletions framalytics/tests/test_fram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@


@pytest.fixture
def simple_xfmv():
def simple_xfmv() -> str:
file = Path(__file__).parent / 'resources/simple_fram.xfmv'
return str(file)


@pytest.fixture
def fram(simple_xfmv):
def fram(simple_xfmv: str) -> framalytics.FRAM:
return framalytics.FRAM(simple_xfmv)


def test_number_of_connections(fram):
def test_number_of_connections(fram: framalytics.FRAM) -> None:
assert fram.number_of_connections() == 8


def test_number_of_functions(fram):
def test_number_of_functions(fram: framalytics.FRAM) -> None:
assert fram.number_of_functions() == 6


def test_get_functions(fram):
def test_get_functions(fram: framalytics.FRAM) -> None:
functions = {0: 'Function A', 1: 'Function B', 2: 'Function C',
3: 'Function D', 4: 'Function E', 5: 'Function F'}

assert fram.get_functions() == functions


def test_get_connections(fram):
def test_get_connections(fram: framalytics.FRAM) -> None:
expected_names = ['Connection CB', 'Connection BA', 'Connection BD',
'Connection CD', 'Connection CE', 'Connection AB',
'Connection FE', 'Connection DE']
Expand All @@ -47,29 +47,29 @@ def test_get_connections(fram):

assert set(connections.Name) == set(expected_names)

expected_fromFns = expected_connections[['Name', 'fromFn']]
expected_fromFns = expected_fromFns.set_index('Name')['fromFn'].to_dict()
fromFns = connections[['Name', 'fromFn']]
fromFns = fromFns.set_index('Name')['fromFn'].to_dict()
tmp = expected_connections[['Name', 'fromFn']]
expected_fromFns = tmp.set_index('Name')['fromFn'].to_dict()
tmp = connections[['Name', 'fromFn']]
fromFns = tmp.set_index('Name')['fromFn'].to_dict()

assert fromFns == expected_fromFns

expected_toFns = expected_connections[['Name', 'toFn']]
expected_toFns = expected_toFns.set_index('Name')['toFn'].to_dict()
toFns = connections[['Name', 'toFn']]
toFns = toFns.set_index('Name')['toFn'].to_dict()
tmp = expected_connections[['Name', 'toFn']]
expected_toFns = tmp.set_index('Name')['toFn'].to_dict()
tmp = connections[['Name', 'toFn']]
toFns = tmp.set_index('Name')['toFn'].to_dict()

assert toFns == expected_toFns

expected_aspects = expected_connections[['Name', 'toAspect']]
expected_aspects = expected_aspects.set_index('Name')['toAspect'].to_dict()
aspects = connections[['Name', 'toAspect']]
aspects = aspects.set_index('Name')['toAspect'].to_dict()
tmp = expected_connections[['Name', 'toAspect']]
expected_aspects = tmp.set_index('Name')['toAspect'].to_dict()
tmp = connections[['Name', 'toAspect']]
aspects = tmp.set_index('Name')['toAspect'].to_dict()

assert aspects == expected_aspects


def test_get_function_name(fram):
def test_get_function_name(fram: framalytics.FRAM) -> None:
assert fram.get_function_name(0) == 'Function A'
assert fram.get_function_name(1) == 'Function B'
assert fram.get_function_name(2) == 'Function C'
Expand All @@ -78,7 +78,7 @@ def test_get_function_name(fram):
assert fram.get_function_name(5) == 'Function F'


def test_get_function_id(fram):
def test_get_function_id(fram: framalytics.FRAM) -> None:
assert fram.get_function_id('Function A') == 0
assert fram.get_function_id('Function B') == 1
assert fram.get_function_id('Function C') == 2
Expand All @@ -94,7 +94,9 @@ def test_get_function_id(fram):
('C', 'get_function_controls'),
('P', 'get_function_preconditions'),
('R', 'get_function_resources')])
def test_get_connection_sources(fram, aspect, get_function):
def test_get_connection_sources(fram: framalytics.FRAM,
aspect: str,
get_function: str) -> None:
"""
get_function_* correctly return the functions connected to each aspect.

Expand Down
59 changes: 31 additions & 28 deletions framalytics/tests/test_xfmv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@


@pytest.fixture
def simple_xfmv():
def simple_xfmv() -> str:
file = Path(__file__).parent / 'resources/simple_fram.xfmv'
return str(file)


@pytest.fixture()
def parsed_xfmv(simple_xfmv):
def parsed_xfmv(simple_xfmv: str) -> tuple[pd.DataFrame, pd.DataFrame]:
return parse_xfmv(simple_xfmv)


def test_return_types(parsed_xfmv):
def test_return_types(parsed_xfmv: tuple[pd.DataFrame, pd.DataFrame]) -> None:
""" Parsing xfmv should return 3 DataFrames. """

functions, connections = parsed_xfmv
Expand All @@ -26,7 +26,7 @@ def test_return_types(parsed_xfmv):
assert isinstance(connections, pd.DataFrame)


def test_function_data(parsed_xfmv):
def test_function_data(parsed_xfmv: tuple[pd.DataFrame, pd.DataFrame]) -> None:
""" Test that function names, ids and types were parsed correctly. """

functions, connections = parsed_xfmv
Expand All @@ -41,18 +41,19 @@ def test_function_data(parsed_xfmv):
assert len(functions) == 6
assert set(functions.IDName.unique()) == set(expected_names)

ids = functions[['IDName', 'IDNr']]
ids = ids.set_index('IDName')['IDNr'].to_dict()
tmp = functions[['IDName', 'IDNr']]
ids = tmp.set_index('IDName')['IDNr'].to_dict()

assert ids == expected_ids

types = functions[['IDName', 'FunctionType']]
types = types.set_index('IDName')['FunctionType'].to_dict()
tmp = functions[['IDName', 'FunctionType']]
types = tmp.set_index('IDName')['FunctionType'].to_dict()

assert types == expected_types


def test_function_positions(parsed_xfmv):
def test_function_positions(parsed_xfmv: tuple[pd.DataFrame,
pd.DataFrame]) -> None:
""" Test that function positions were parsed correctly. """

functions, connections = parsed_xfmv
Expand Down Expand Up @@ -82,7 +83,8 @@ def test_function_positions(parsed_xfmv):
assert y == pytest.approx(186.66, abs=1e-2)


def test_connection_raw_name(parsed_xfmv):
def test_connection_raw_name(parsed_xfmv: tuple[pd.DataFrame,
pd.DataFrame]) -> None:
""" Test that the raw connection name was parsed correctly. """

functions, connections = parsed_xfmv
Expand All @@ -93,10 +95,11 @@ def test_connection_raw_name(parsed_xfmv):
'5|Connection FE|4|R', '3|Connection DE|4|P']

assert len(connections) == 8
assert set(connections.Name.unique()) == set(connection_raw_names)
assert set(connections['Name'].unique()) == set(connection_raw_names)


def test_connection_names(parsed_xfmv):
def test_connection_names(parsed_xfmv: tuple[pd.DataFrame,
pd.DataFrame]) -> None:
""" Test that connection data was parsed correctly. """

functions, connections = parsed_xfmv
Expand All @@ -118,30 +121,30 @@ def test_connection_names(parsed_xfmv):
'outputFn': connection_outputFns,
'toFn': connection_toFns})

expected_names = connection_data[['Name', 'parsed_name']]
expected_names = expected_names.set_index('Name')['parsed_name'].to_dict()
names = connections[['Name', 'parsed_name']]
names = names.set_index('Name')['parsed_name'].to_dict()
tmp = connection_data[['Name', 'parsed_name']]
expected_names = tmp.set_index('Name')['parsed_name'].to_dict()
tmp = connections[['Name', 'parsed_name']]
names = tmp.set_index('Name')['parsed_name'].to_dict()

assert names == expected_names

expected_aspects = connection_data[['Name', 'toAspect']]
expected_aspects = expected_aspects.set_index('Name')['toAspect'].to_dict()
aspects = connections[['Name', 'toAspect']]
aspects = aspects.set_index('Name')['toAspect'].to_dict()
tmp = connection_data[['Name', 'toAspect']]
expected_aspects = tmp.set_index('Name')['toAspect'].to_dict()
tmp = connections[['Name', 'toAspect']]
aspects = tmp.set_index('Name')['toAspect'].to_dict()

assert aspects == expected_aspects

expected_outputs = connection_data[['Name', 'outputFn']]
expected_outputs = expected_outputs.set_index('Name')['outputFn'].to_dict()
outputs = connections[['Name', 'outputFn']]
outputs = outputs.set_index('Name')['outputFn'].to_dict()
tmp = connection_data[['Name', 'outputFn']]
expected_outputs = tmp.set_index('Name')['outputFn'].to_dict()
tmp = connections[['Name', 'outputFn']]
outputs = tmp.set_index('Name')['outputFn'].to_dict()

assert outputs == expected_outputs

expected_toFns = connection_data[['Name', 'toFn']]
expected_toFns = expected_toFns.set_index('Name')['toFn'].to_dict()
toFns = connections[['Name', 'toFn']]
toFns = toFns.set_index('Name')['toFn'].to_dict()
tmp = connection_data[['Name', 'toFn']]
expected_toFns = tmp.set_index('Name')['toFn'].to_dict()
tmp = connections[['Name', 'toFn']]
toFns = tmp.set_index('Name')['toFn'].to_dict()

assert toFns == expected_toFns