-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ouhammmourachid/update-test
add save methode to graph class to save the script in a seperte file …
- Loading branch information
Showing
6 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
""" a beter docs sttrings | ||
""" | ||
from ._utils import read_file | ||
from ._utils import load | ||
from .mermaid import * | ||
|
||
__version__: str = '0.1.5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import os | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
|
||
@dataclass | ||
class Graph: | ||
name: str | ||
script: str | ||
|
||
def save(self, path: Optional[Path] = None) -> None: | ||
file_path: Path = path if path else Path(f'./{self.name}.txt') | ||
|
||
with open(file_path, 'w') as file: | ||
file.write(self.script) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import unittest | ||
from pathlib import Path | ||
|
||
from mermaid.graph import Graph | ||
|
||
|
||
class TestGraph(unittest.TestCase): | ||
def setUp(self) -> None: | ||
script: str = """graph TD; | ||
A-->B; | ||
A-->C; | ||
B-->D; | ||
C-->D;""" | ||
self.graph_test: Graph = Graph('test-graph', script) | ||
return super().setUp() | ||
|
||
def test_save_graph_without_path(self) -> None: | ||
self.graph_test.save() | ||
self.assertTrue(Path.exists(Path('./test-graph.txt'))) | ||
|
||
def test_save_graph_with_path(self) -> None: | ||
self.graph_test.save(Path('./test-graph-file.txt')) | ||
self.assertTrue(Path.exists(Path('./test-graph-file.txt'))) | ||
|
||
def tearDown(self) -> None: | ||
if os.path.exists('./test-graph.txt'): | ||
os.remove('./test-graph.txt') | ||
if os.path.exists('./test-graph-file.txt'): | ||
os.remove('./test-graph-file.txt') | ||
return super().tearDown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
import os | ||
import unittest | ||
|
||
import mermaid as md | ||
from mermaid.graph import Graph | ||
|
||
|
||
class TestUtils(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.file_test: str = './tests/test-graph.txt' | ||
with open(self.file_test, 'w') as file: | ||
file.write("""graph TD; | ||
A-->B; | ||
A-->C; | ||
B-->D; | ||
C-->D;""") | ||
return super().setUp() | ||
|
||
def test_read_file_should_raise_error(self): | ||
with self.assertRaises(FileNotFoundError): | ||
md.read_file('./file.txt') | ||
md.load('./file.txt') | ||
|
||
def test_read_file(self): | ||
graph: Graph = md.read_file('./tests/test-graph.txt') | ||
graph: Graph = md.load('./tests/test-graph.txt') | ||
expect_name: str = 'test-graph' | ||
expect_script: str = """graph TD; | ||
A-->B; | ||
A-->C; | ||
B-->D; | ||
C-->D;\n""" | ||
C-->D;""" | ||
self.assertEqual(graph.name, expect_name) | ||
self.assertEqual(graph.script, expect_script) | ||
|
||
def tearDown(self) -> None: | ||
if os.path.exists(self.file_test): | ||
os.remove(self.file_test) | ||
return super().tearDown() |