Skip to content

Commit

Permalink
tests: cover disabled labels in infrastructures
Browse files Browse the repository at this point in the history
Tests differences when rack, row and equipments are either enabled or
disabled in infrastructures graphical representations.
  • Loading branch information
rezib committed Dec 3, 2024
1 parent e469407 commit 1dc2888
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions racksdb/tests/drawers/test_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import unittest
from unittest import mock
import tempfile
from pathlib import Path

Expand Down Expand Up @@ -67,3 +68,76 @@ def test_draw_not_existing_infrastructure(self):
self.db, "fail", filename, "png", self.parameters, None, "yaml"
)
self.assertFalse(filename.exists())

def test_rack_row_spacing_height(self):
drawer = InfrastructureDrawer(
self.db, "mercury", "dontmind.png", "png", self.parameters, None, "yaml"
)
# Check that by default, row and racks labels are enabled.
self.assertTrue(self.parameters.rack.labels)
self.assertTrue(self.parameters.row.labels)

# Change values of rack offset and rack label offset to validate sums.
self.assertEqual(self.parameters.row.label_offset, 20)
self.parameters.rack.offset = 10
self.parameters.rack.label_offset = 30

# Check spacing height between rows with all labels enabled.
self.assertEqual(drawer._rack_row_spacing_height(), 60) # 30 + 20 + 10
# Disable racks labels.
self.parameters.rack.labels = False
self.assertEqual(drawer._rack_row_spacing_height(), 30) # 20 + 10
# Disable row labels (ie. no labels).
self.parameters.row.labels = False
self.assertEqual(drawer._rack_row_spacing_height(), 10)
# Re-enable racks labels (w/o row labels).
self.parameters.rack.labels = True
self.assertEqual(drawer._rack_row_spacing_height(), 40) # 30 + 10

def test_labels_call_print_text(self):
with tempfile.TemporaryDirectory() as tmpdir:
filename = Path(tmpdir) / "output.png"
drawer = InfrastructureDrawer(
self.db, "mercury", filename, "png", self.parameters, None, "yaml"
)
# Mock _print_text() method to check if it is called or not.
drawer._print_text = mock.Mock()

# Check _print_text() is not called when all labels are disabled.
(
self.parameters.rack.labels,
self.parameters.row.labels,
self.parameters.infrastructure.equipment_labels,
) = (False, False, False)
drawer.draw()
drawer._print_text.assert_not_called()
drawer._print_text.reset_mock()

# Check _print_text() is called when either rack, row or equipment
# labels are enabled.
(
self.parameters.rack.labels,
self.parameters.row.labels,
self.parameters.infrastructure.equipment_labels,
) = (True, False, False)
drawer.draw()
drawer._print_text.assert_called()
drawer._print_text.reset_mock()

(
self.parameters.rack.labels,
self.parameters.row.labels,
self.parameters.infrastructure.equipment_labels,
) = (False, True, False)
drawer.draw()
drawer._print_text.assert_called()
drawer._print_text.reset_mock()

(
self.parameters.rack.labels,
self.parameters.row.labels,
self.parameters.infrastructure.equipment_labels,
) = (False, False, True)
drawer.draw()
drawer._print_text.assert_called()
drawer._print_text.reset_mock()

0 comments on commit 1dc2888

Please sign in to comment.