Browse Source

command intertechno-cc1101: no longer allow abbreviation of options / flags; added tests

Fabian Peter Hammerle 3 years ago
parent
commit
cb306de049
3 changed files with 39 additions and 1 deletions
  1. 2 0
      CHANGELOG.md
  2. 2 1
      intertechno_cc1101/_cli.py
  3. 35 0
      tests/test_cli.py

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Changed
+- command `intertechno-cc1101`: no longer allow abbreviation of options / flags
 
 ## [0.1.0] - 2021-02-04
 ### Added

+ 2 - 1
intertechno_cc1101/_cli.py

@@ -8,7 +8,8 @@ _LOGGER = logging.getLogger(__name__)
 
 def _main():
     argparser = argparse.ArgumentParser(
-        description="Control Intertechno Outlets via CC1101 Transceivers"
+        description="Control Intertechno Outlets via CC1101 Transceivers",
+        allow_abbrev=False,
     )
     argparser.add_argument(
         "-a",

+ 35 - 0
tests/test_cli.py

@@ -0,0 +1,35 @@
+import unittest.mock
+
+import pytest
+
+import intertechno_cc1101._cli
+
+# pylint: disable=protected-access
+
+
+@pytest.mark.parametrize(
+    ("argv", "address", "button_index", "turn_on"),
+    (
+        (["-a", "12345678", "-1"], 12345678, 0, True),
+        (["-a", "12345678", "-0"], 12345678, 0, False),
+        (["--address", "12345678", "--turn-on"], 12345678, 0, True),
+        (["-a", "12345678", "--turn-off"], 12345678, 0, False),
+        (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True),
+    ),
+)
+def test__main(argv, address, button_index, turn_on):
+    with unittest.mock.patch(
+        "intertechno_cc1101.RemoteControl"
+    ) as remote_control_class_mock, unittest.mock.patch("sys.argv", [""] + argv):
+        intertechno_cc1101._cli._main()
+    remote_control_class_mock.assert_called_once_with(address=address)
+    if turn_on:
+        remote_control_class_mock().turn_on.assert_called_once_with(
+            button_index=button_index
+        )
+        remote_control_class_mock().turn_off.assert_not_called()
+    else:
+        remote_control_class_mock().turn_off.assert_called_once_with(
+            button_index=button_index
+        )
+        remote_control_class_mock().turn_on.assert_not_called()