-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: partially cover InfrastructureDrawer
Add first tests to partially cover InfrastructureDrawer class. Some refactoring is done to share some code in new tests.lib module.
- Loading branch information
Showing
6 changed files
with
129 additions
and
45 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright (c) 2023 Rackslab | ||
# | ||
# This file is part of RacksDB. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import unittest | ||
import tempfile | ||
from pathlib import Path | ||
|
||
from racksdb import RacksDB | ||
from racksdb.drawers.infrastructure import InfrastructureDrawer | ||
from racksdb.drawers.parameters import DrawingParameters | ||
from racksdb.generic.db import DBDictsLoader | ||
from racksdb.errors import RacksDBError | ||
|
||
from ..lib.common import drawing_schema_path, schema_path, db_path | ||
|
||
|
||
class TestInfrastructureDrawer(unittest.TestCase): | ||
def setUp(self): | ||
try: | ||
self.drawings_schema_path = drawing_schema_path() | ||
self.schema_path = schema_path() | ||
self.db_path = db_path() | ||
except FileNotFoundError as err: | ||
self.skipTest(err) | ||
self.parameters = DrawingParameters.load( | ||
DBDictsLoader({}), self.drawings_schema_path | ||
) | ||
self.db = RacksDB.load(schema=self.schema_path, db=self.db_path) | ||
|
||
def test_draw_png(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
filename = Path(tmpdir) / "output.png" | ||
drawer = InfrastructureDrawer( | ||
self.db, "mercury", filename, "png", self.parameters, None, "yaml" | ||
) | ||
drawer.draw() | ||
self.assertTrue(filename.exists()) | ||
|
||
def test_draw_svg(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
filename = Path(tmpdir) / "output.svg" | ||
drawer = InfrastructureDrawer( | ||
self.db, "mercury", filename, "svg", self.parameters, None, "yaml" | ||
) | ||
drawer.draw() | ||
self.assertTrue(filename.exists()) | ||
|
||
def test_draw_pdf(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
filename = Path(tmpdir) / "output.pdf" | ||
drawer = InfrastructureDrawer( | ||
self.db, "mercury", filename, "pdf", self.parameters, None, "yaml" | ||
) | ||
drawer.draw() | ||
self.assertTrue(filename.exists()) | ||
|
||
def test_draw_not_existing_infrastructure(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
filename = Path(tmpdir) / "output.png" | ||
with self.assertRaisesRegex( | ||
RacksDBError, "^Unable to find infrastructure fail in database$" | ||
): | ||
InfrastructureDrawer( | ||
self.db, "fail", filename, "png", self.parameters, None, "yaml" | ||
) | ||
self.assertFalse(filename.exists()) |
Empty file.
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,47 @@ | ||
# Copyright (c) 2023 Rackslab | ||
# | ||
# This file is part of RacksDB. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def _first_path(paths, error): | ||
for path in paths: | ||
if path.exists(): | ||
return path | ||
raise FileNotFoundError(error) | ||
|
||
|
||
def drawing_schema_path(): | ||
return _first_path( | ||
[ | ||
Path(CURRENT_DIR).joinpath("../../../schemas/drawings.yml"), | ||
Path("/usr/share/racksdb/schemas/drawings.yml"), | ||
], | ||
"Unable to find drawing schema to run tests", | ||
) | ||
|
||
|
||
def schema_path(): | ||
return _first_path( | ||
[ | ||
Path(CURRENT_DIR).joinpath("../../schemas/racksdb.yml"), | ||
Path("/usr/share/racksdb/schemas/racksdb.yml"), | ||
], | ||
"Unable to find schema to run tests", | ||
) | ||
|
||
|
||
def db_path(): | ||
return _first_path( | ||
[ | ||
Path(CURRENT_DIR).joinpath("../../../examples/db"), | ||
Path("/usr/share/doc/racksdb/examples/db"), | ||
], | ||
"Unable to find database to run tests", | ||
) |
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