Skip to content

Commit

Permalink
Tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ingrinder committed Apr 13, 2024
1 parent 76cfe31 commit d17dfc7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 84 deletions.
52 changes: 12 additions & 40 deletions archey/test/entries/test_archey_load_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ def test_pretty_value_coloration(self):
"danger_threshold": 2.25,
}

self.assertListEqual(
list(self.load_average_mock),
[
(
self.load_average_mock.name,
f"{Colors.GREEN_NORMAL}0.5{Colors.CLEAR} "
f"{Colors.YELLOW_NORMAL}1.25{Colors.CLEAR} "
f"{Colors.RED_NORMAL}2.5{Colors.CLEAR}",
)
],
self.assertEqual(
str(self.load_average_mock),
f"{Colors.GREEN_NORMAL}0.5{Colors.CLEAR} {Colors.YELLOW_NORMAL}1.25{Colors.CLEAR} {Colors.RED_NORMAL}2.5{Colors.CLEAR}",
)

@HelperMethods.patch_clean_configuration
Expand All @@ -46,16 +39,9 @@ def test_pretty_value_rounding(self):
"warning_threshold": 5,
"danger_threshold": 5,
}
self.assertListEqual(
list(self.load_average_mock),
[
(
self.load_average_mock.name,
f"{Colors.GREEN_NORMAL}0.0{Colors.CLEAR} "
f"{Colors.GREEN_NORMAL}1.0{Colors.CLEAR} "
f"{Colors.GREEN_NORMAL}2.0{Colors.CLEAR}",
)
],
self.assertEqual(
str(self.load_average_mock),
f"{Colors.GREEN_NORMAL}0.0{Colors.CLEAR} {Colors.GREEN_NORMAL}1.0{Colors.CLEAR} {Colors.GREEN_NORMAL}2.0{Colors.CLEAR}",
)

with self.subTest("1 decimal place"):
Expand All @@ -64,16 +50,9 @@ def test_pretty_value_rounding(self):
"warning_threshold": 5,
"danger_threshold": 5,
}
self.assertListEqual(
list(self.load_average_mock),
[
(
self.load_average_mock.name,
f"{Colors.GREEN_NORMAL}0.3{Colors.CLEAR} "
f"{Colors.GREEN_NORMAL}1.2{Colors.CLEAR} "
f"{Colors.GREEN_NORMAL}2.0{Colors.CLEAR}",
)
],
self.assertEqual(
str(self.load_average_mock),
f"{Colors.GREEN_NORMAL}0.3{Colors.CLEAR} {Colors.GREEN_NORMAL}1.2{Colors.CLEAR} {Colors.GREEN_NORMAL}2.0{Colors.CLEAR}",
)

with self.subTest("2 decimal places"):
Expand All @@ -82,16 +61,9 @@ def test_pretty_value_rounding(self):
"warning_threshold": 5,
"danger_threshold": 5,
}
self.assertListEqual(
list(self.load_average_mock),
[
(
self.load_average_mock.name,
f"{Colors.GREEN_NORMAL}0.33{Colors.CLEAR} "
f"{Colors.GREEN_NORMAL}1.25{Colors.CLEAR} "
f"{Colors.GREEN_NORMAL}2.0{Colors.CLEAR}",
)
],
self.assertEqual(
str(self.load_average_mock),
f"{Colors.GREEN_NORMAL}0.33{Colors.CLEAR} {Colors.GREEN_NORMAL}1.25{Colors.CLEAR} {Colors.GREEN_NORMAL}2.0{Colors.CLEAR}",
)


Expand Down
4 changes: 0 additions & 4 deletions archey/test/entries/test_archey_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ def test_no_match(self):
"""Test when no information could be retrieved"""
model_instance_mock = HelperMethods.entry_mock(Model)
self.assertIsNone(model_instance_mock.value)
self.assertListEqual(
list(model_instance_mock),
[(model_instance_mock.name, None)],
)

@patch(
"archey.entries.model.check_output",
Expand Down
4 changes: 0 additions & 4 deletions archey/test/entries/test_archey_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@ def test_no_packages_manager(self, check_output_mock):
packages = Packages()

self.assertIsNone(packages.value)
self.assertListEqual(
list(packages),
[(packages.name, None)],
)

@staticmethod
def _check_output_side_effect(pkg_manager_cmd=None):
Expand Down
29 changes: 8 additions & 21 deletions archey/test/entries/test_archey_ram.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ def test_various_output_configuration(self):
"""Test output overloading based on user preferences"""
ram_instance_mock = HelperMethods.entry_mock(RAM)

with self.subTest("Output in case of non-detection."):
self.assertListEqual(
list(ram_instance_mock),
[(ram_instance_mock.name, None)],
)
with self.subTest("In case of non-detection."):
self.assertIsNone(ram_instance_mock.value)

with self.subTest('"Normal" output (green).'):
ram_instance_mock.value = {
Expand All @@ -143,14 +140,9 @@ def test_various_output_configuration(self):
"warning_use_percent": 33.3,
"danger_use_percent": 66.7,
}
self.assertListEqual(
list(ram_instance_mock),
[
(
ram_instance_mock.name,
f"{Colors.GREEN_NORMAL}2043 MiB{Colors.CLEAR} / 15658 MiB",
)
],
self.assertEqual(
str(ram_instance_mock),
f"{Colors.GREEN_NORMAL}2043 MiB{Colors.CLEAR} / 15658 MiB",
)

with self.subTest('"Danger" output (red).'):
Expand All @@ -163,14 +155,9 @@ def test_various_output_configuration(self):
"warning_use_percent": 25,
"danger_use_percent": 50,
}
self.assertListEqual(
list(ram_instance_mock),
[
(
ram_instance_mock.name,
f"{Colors.RED_NORMAL}7830 MiB{Colors.CLEAR} / 15658 MiB",
)
],
self.assertEqual(
str(ram_instance_mock),
f"{Colors.RED_NORMAL}7830 MiB{Colors.CLEAR} / 15658 MiB",
)


Expand Down
4 changes: 0 additions & 4 deletions archey/test/entries/test_archey_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ def test_config_fall_back(self, _, __):
"""`id` fails, but Archey must not !"""
shell = Shell()
self.assertIsNone(shell.value)
self.assertListEqual(
list(shell),
[(shell.name, None)],
)


if __name__ == "__main__":
Expand Down
16 changes: 5 additions & 11 deletions archey/test/entries/test_archey_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,7 @@ def test_run_vcgencmd(self, _):
def test_output(self):
"""Test output values"""
# No value --> `None`.
self.assertListEqual(
list(self.temperature_mock),
[(self.temperature_mock.name, None)],
)
self.assertIsNone(self.temperature_mock.value)

# Values --> normal behavior.
self.temperature_mock._temps = [50.0, 40.0, 50.0] # pylint: disable=protected-access
Expand All @@ -348,9 +345,9 @@ def test_output(self):
"char_before_unit": "o",
"unit": "C",
}
self.assertListEqual(
list(self.temperature_mock),
[(self.temperature_mock.name, "46.7oC (Max. 50.0oC)")],
self.assertEqual(
str(self.temperature_mock),
"46.7oC (Max. 50.0oC)",
)

# Only one value --> no maximum.
Expand All @@ -361,10 +358,7 @@ def test_output(self):
"char_before_unit": " ",
"unit": "C",
}
self.assertListEqual(
list(self.temperature_mock),
[(self.temperature_mock.name, "42.8 C")],
)
self.assertEqual(str(self.temperature_mock), "42.8 C")

def test_convert_to_fahrenheit(self):
"""Simple tests for the `_convert_to_fahrenheit` static method"""
Expand Down

0 comments on commit d17dfc7

Please sign in to comment.