From 5c1ebd3d54a615a761e1ba81d2473a34f002fdd6 Mon Sep 17 00:00:00 2001 From: Robin Quintero Date: Sun, 5 Nov 2023 00:00:20 -0500 Subject: [PATCH] feat(view): #4 enable graphviz customization - Upgrade the view function to accept graphviz attributes. - Update the README.md file with CI status badge. --- automathon/finiteAutomata/dfa.py | 6 ++++-- automathon/finiteAutomata/nfa.py | 6 ++++-- tests/test_nfa.py | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/automathon/finiteAutomata/dfa.py b/automathon/finiteAutomata/dfa.py index a2dd3ab..12edc91 100644 --- a/automathon/finiteAutomata/dfa.py +++ b/automathon/finiteAutomata/dfa.py @@ -1,4 +1,6 @@ # Exceptions module +from __future__ import annotations + from automathon.errors.errors import * from collections import deque from graphviz import Digraph @@ -218,8 +220,8 @@ def union(self, M: 'DFA') -> 'DFA': return tmp_nfa.get_dfa() - def view(self, fileName: str): - dot = Digraph(name=fileName, format='png') + def view(self, file_name: str, node_attr: dict[str, str] | None = None, edge_attr: dict[str, str] | None = None): + dot = Digraph(name=file_name, format='png', node_attr=node_attr, edge_attr=edge_attr) dot.graph_attr['rankdir'] = 'LR' diff --git a/automathon/finiteAutomata/nfa.py b/automathon/finiteAutomata/nfa.py index d0d0c94..ba88362 100644 --- a/automathon/finiteAutomata/nfa.py +++ b/automathon/finiteAutomata/nfa.py @@ -1,4 +1,6 @@ # Exceptions module +from __future__ import annotations + from automathon.errors.errors import * from collections import deque from graphviz import Digraph @@ -400,8 +402,8 @@ def product(self, M: 'NFA') -> 'NFA': return nfa - def view(self, file_name: str): - dot = Digraph(name=file_name, format='png') + def view(self, file_name: str, node_attr: dict[str, str] | None = None, edge_attr: dict[str, str] | None = None): + dot = Digraph(name=file_name, format='png', node_attr=node_attr, edge_attr=edge_attr) dot.graph_attr['rankdir'] = 'LR' diff --git a/tests/test_nfa.py b/tests/test_nfa.py index 793d2e1..23a55f6 100644 --- a/tests/test_nfa.py +++ b/tests/test_nfa.py @@ -181,3 +181,7 @@ def test_renumber(self): automata_4.renumber() self.assertTrue(automata_4.is_valid()) + + +if __name__ == '__main__': + unittest.main()