diff --git a/contrib/nuc_wmi/Makefile b/contrib/nuc_wmi/Makefile index ddf6393..4650b8d 100644 --- a/contrib/nuc_wmi/Makefile +++ b/contrib/nuc_wmi/Makefile @@ -8,4 +8,5 @@ deb: nosetests: python setup.py nosetests --cover-branches --cover-html --cover-html-dir ./cover --cover-package nuc_wmi -d -s -v --with-coverage --py3where python/ test: + pylint python/nuc_wmi python/test/ python setup.py test diff --git a/contrib/nuc_wmi/README.md b/contrib/nuc_wmi/README.md index e662bbe..59abe3b 100644 --- a/contrib/nuc_wmi/README.md +++ b/contrib/nuc_wmi/README.md @@ -121,7 +121,7 @@ package in the form of a `wheel`, `egg`, or distro specific package using `setup ## Testing Use your system's package manager to install your choice of `python` version and `coverage`, `mock`, `nose`, `nose-cov`, -and `setuptools` Python packages. +`pylint`, and `setuptools` Python packages. Clean directory: @@ -135,6 +135,7 @@ find . -type d -name "__pycache__" -exec rmdir {} + Run tests: ``` +pylint python/nuc_wmi python/test/ python setup.py test ``` @@ -162,6 +163,7 @@ $ nuc_wmi-get_led 'S0 Power LED' $ nuc_wmi-get_led 'S0 Ring LED' {"led": {"color": "White", "frequency": "Always on", "type": "S0 Ring LED", "brightness": "100"}} +# Brightness is an integer percentage 0-100 and not the internal WMI hex value. $ nuc_wmi-set_led 'S0 Ring LED' 100 'Always on' 'White' {"led": {"color": "White", "frequency": "Always on", "type": "S0 Ring LED", "brightness": "100"}} ``` @@ -171,12 +173,15 @@ $ nuc_wmi-set_led 'S0 Ring LED' 100 'Always on' 'White' ``` $ nuc_wmi-get_led_control_item 'HDD LED' 'Software Indicator' 'Brightness' {"led": {"control_item": "Brightness", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "100"}} +# For BIOS where the HDD LED LED color type is "Dual-color Blue / White" $ nuc_wmi-get_led_control_item 'HDD LED' 'Software Indicator' 'Color' {"led": {"control_item": "Color", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "White"}} $ nuc_wmi-get_led_control_item 'Power Button LED' 'Power State Indicator' 'S0 Indicator Color' {"led": {"control_item": "S0 Indicator Color", "type": "Power Button LED", "indicator_option": "Power State Indicator", "control_item_value": "Blue"}} $ nuc_wmi-get_led_control_item 'Power Button LED' 'Power State Indicator' 'S0 Indicator Brightness' {"led": {"control_item": "S0 Indicator Brightness", "type": "Power Button LED", "indicator_option": "Power State Indicator", "control_item_value": "50"}} +$ nuc_wmi-get_led_control_item 'HDD LED' 'Software Indicator' 'Blinking Frequency' +{"led": {"control_item": "Blinking Frequency", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "1.0Hz"}} $ nuc_wmi-get_led_indicator_option 'HDD LED' {"led": {"type": "HDD LED", "indicator_option": "Software Indicator"}} @@ -187,6 +192,8 @@ $ nuc_wmi-query_led_color_type 'HDD LED' {"led": {"color_type": "Dual-color Blue / White", "type": "HDD LED"}} $ nuc_wmi-query_led_color_type 'Power Button LED' {"led": {"color_type": "Dual-color Blue / Amber", "type": "Power Button LED"}} +$ nuc_wmi-query_led_color_type 'HDD LED' +{"led": {"color_type": "RGB-color", "type": "HDD LED"}} $ nuc_wmi-query_led_control_items 'Power Button LED' 'Power State Indicator' {"led": {"control_items": ["S0 Indicator Brightness", "S0 Indicator Blinking Behavior", "S0 Indicator Blinking Frequency", "S0 Indicator Color"], "type": "Power Button LED", "indicator_option": "Power State Indicator"}} @@ -202,16 +209,35 @@ $ nuc_wmi-query_led_indicator_options 'HDD LED' $ nuc_wmi-query_led_indicator_options 'Power Button LED' {"led": {"type": "Power Button LED", "indicator_options": ["Power State Indicator", "HDD Activity Indicator", "Software Indicator"]}} +# RGB Header is only available if on the latest BIOS $ nuc_wmi-query_leds -{"leds": ["Power Button LED", "HDD LED"]} +{"leds": ["Power Button LED", "HDD LED", "RGB Header"]} $ nuc_wmi-save_led_config {"led_app_notification": {"type": "save_led_config"}} +# Brightness is an integer percentage 0-100 and not the internal WMI hex value. $ nuc_wmi-set_led_control_item 'HDD LED' 'Software Indicator' 'Brightness' 100 {"led": {"control_item": "Brightness", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "100"}} +# Blinking Frequency is 0.1Hz-1.0Hz +$ nuc_wmi-set_led_control_item 'HDD LED' 'Software Indicator' 'Blinking Frequency' '1.0Hz' +{"led": {"control_item": "Blinking Frequency", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "1.0Hz"}} $ nuc_wmi-set_led_control_item 'Power Button LED' 'Power State Indicator' 'S0 Indicator Color' Blue {"led": {"control_item": "S0 Indicator Color", "type": "Power Button LED", "indicator_option": "Power State Indicator", "control_item_value": "Blue"}} +# For BIOS where the HDD LED LED color type is "RGB-color" but 1D (where only 'Color' is a supported control item) +$ nuc_wmi-set_led_control_item 'HDD LED' 'Software Indicator' 'Color' 'Indigo' +{"led": {"control_item": "Color", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "Indigo"}} +# For LEDs where the color type is RGB-color but 3D, the color is controlled by 3 dimension settings (one for Red, Green, and Blue respectively) that accept +# an integer value from 0-255 for each color dimension. There may be multiple control item triplets for RGB colors per indicator option. For +# this example we pretend the HDD LED reports its color type as RGB-color and we set the LED to Red (you must set all 3 dimensions to ensure you end up with the correct color). +# If you want to avoid having the color change as you set the dimensions, your only option is to drop the brightness down to 0 before settng the color and back to a +# non zero brightness once its set. +$ nuc_wmi-set_led_control_item 'HDD LED' 'Software Indicator' 'Color' '255' # Red dimension +{"led": {"control_item": "Color", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "255"}} +$ nuc_wmi-set_led_control_item 'HDD LED' 'Software Indicator' 'Color 2' '0' # Green dimension +{"led": {"control_item": "Color 2", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "0"}} +$ nuc_wmi-set_led_control_item 'HDD LED' 'Software Indicator' 'Color 3' '0' # Blue dimension +{"led": {"control_item": "Color 3", "type": "HDD LED", "indicator_option": "Software Indicator", "control_item_value": "0"}} $ nuc_wmi-set_led_indicator_option 'HDD LED' 'Software Indicator' {"led": {"type": "HDD LED", "indicator_option": "Software Indicator"}} @@ -225,3 +251,32 @@ $ nuc_wmi-switch_led_type 'Multi color LED' $ nuc_wmi-wmi_interface_spec_compliance_version {"version": {"semver": "1.32", "type": "wmi_interface_spec_compliance"}} ``` +## Quirks Mode + +Unfortunately there can be a large set of differences across the devices and sometimes bugs in the BIOS +implementation make it out into the wild. All CLI commands support `quirks mode` via the `-q` and `--quirks` +CLI options. + +### NUC 7 Quirks + +* `NUC7_FREQUENCY_DEFAULT`: This `quirks mode` changes the processing of the return value for the `get_led` + WMI method for NUC 7 BIOS. This affects NUC 7 in a factory default state where the NUC LEDs state hasnt been changed. + In a factory default state, the NUC 7 can properly return `0` for `brightness` and `0` for `color` (aka `Disabled`), + however it also returns `0` for `frequency` which is an invalid enum value according to the documentation. Enabling + this quirks mode overrides any `0` value returned for `frequency` and converts it to `1` for `1Hz`. Enabling this + quirks mode on a BIOS not affected by this issue will not cause a change in the return value for `frequency`. + +### NUC 10 Quirks + +* `NUC10_RETURN_VALUE`: This `quirks mode` changes the processing of the return value for the `query_led_color_type` + and `get_led_indicator_option` WMI methods for NUC 10 BIOS released before December 2020 that also did not support + the NUC 10 RGB header. In NUC 10 BIOS released before December 2020, the implementation for these two WMI methods do + not follow the spec, therefore they are only compatible `nuc_wmi` `1.0`. If you have the December 2020 or later BIOS, + then `nuc_wmi` `1.1` or later is required. `nuc_wmi` `2.1` was the first version to support this `quirks mode` so + any version `2.1` or greater supports all these BIOS. + + In order to determine whether or not you need to enable this `quirks mode`, you can run `nuc_wmi-query_leds` and + if `RGB Header` is not an option then you will likely have to enable this `quirk`. Note that although only + `query_led_color_type` and `get_led_indicator_option` WMI method's return value processing is affected, some of the + other `nuc_wmi` CLI functions may call these two functions when processing CLI arguments, therefore you should always + enable this `quirks mode` if your BIOS version is old enough to be affected by it. diff --git a/contrib/nuc_wmi/pylintrc b/contrib/nuc_wmi/pylintrc new file mode 100644 index 0000000..dec0c34 --- /dev/null +++ b/contrib/nuc_wmi/pylintrc @@ -0,0 +1,553 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +jobs=1 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +disable=print-statement, + parameter-unpacking, + unpacking-in-except, + old-raise-syntax, + backtick, + long-suffix, + old-ne-operator, + old-octal-literal, + import-star-module-level, + non-ascii-bytes-literal, + invalid-unicode-literal, + raw-checker-failed, + bad-inline-option, + locally-disabled, + locally-enabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + apply-builtin, + basestring-builtin, + buffer-builtin, + cmp-builtin, + coerce-builtin, + execfile-builtin, + file-builtin, + long-builtin, + raw_input-builtin, + reduce-builtin, + standarderror-builtin, + unicode-builtin, + xrange-builtin, + coerce-method, + delslice-method, + getslice-method, + setslice-method, + no-absolute-import, + old-division, + dict-iter-method, + dict-view-method, + next-method-called, + metaclass-assignment, + indexing-exception, + raising-string, + reload-builtin, + oct-method, + hex-method, + nonzero-method, + cmp-method, + input-builtin, + round-builtin, + intern-builtin, + unichr-builtin, + map-builtin-not-iterating, + zip-builtin-not-iterating, + range-builtin-not-iterating, + filter-builtin-not-iterating, + using-cmp-argument, + eq-without-hash, + div-method, + idiv-method, + rdiv-method, + exception-message-attribute, + invalid-str-codec, + sys-max-int, + bad-python3-import, + deprecated-string-function, + deprecated-str-translate-call, + deprecated-itertools-function, + deprecated-types-field, + next-method-defined, + dict-items-not-iterating, + dict-keys-not-iterating, + dict-values-not-iterating, + deprecated-operator-function, + deprecated-urllib-function, + xreadlines-attribute, + deprecated-sys-function, + exception-escape, + comprehension-escape, + duplicate-code, + assignment-from-no-return, + raise-missing-from, + too-many-lines + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=optparse.Values,sys.exit + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,io,builtins + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + + +[BASIC] + +# Naming style matching correct argument names +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style +#argument-rgx= + +# Naming style matching correct attribute names +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Naming style matching correct class attribute names +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style +#class-attribute-rgx= + +# Naming style matching correct class names +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming-style +#class-rgx= + +# Naming style matching correct constant names +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma +good-names=i, + j, + k, + ex, + Run, + _ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming style matching correct inline iteration names +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style +#inlinevar-rgx= + +# Naming style matching correct method names +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style +#method-rgx= + +# Naming style matching correct module names +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Naming style matching correct variable names +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style +#variable-rgx= + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=120 + +# Maximum number of lines in a module +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma, + dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub, + TERMIOS, + Bastion, + rexec + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of statements in function / method body +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/contrib/nuc_wmi/python/nuc_wmi/__init__.py b/contrib/nuc_wmi/python/nuc_wmi/__init__.py index bdb2ff7..254f9c8 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/__init__.py +++ b/contrib/nuc_wmi/python/nuc_wmi/__init__.py @@ -49,8 +49,19 @@ '0.25Hz fade', '0.5Hz fade' ], - # 0x00 is not supported but we have to add it so its indexed right. - 'new': [str(freq) for freq in range(0x00, 0x0A + 1)] + 'new': [ + None, + '0.1Hz', + '0.2Hz', + '0.3Hz', + '0.4Hz', + '0.5Hz', + '0.6Hz', + '0.7Hz', + '0.8Hz', + '0.9Hz', + '1.0Hz' + ] } LED_BRIGHTNESS_MULTI_COLOR = [str(brightness) for brightness in range(0x00, 0x64 + 1)] @@ -107,7 +118,32 @@ 'Blue', 'White' ], - 'RGB-color': [str(rgb) for rgb in range(0x00, 0xFF + 1)] + 'RGB-color': { + '1d': { + 'HDD LED': [ + None, + 'Blue', + 'Red', + 'Green', + 'Orange', + 'Yellow', + 'Indigo', + 'Violet', + 'White' + ], + 'RGB Header': [ + None, + 'Cyan', + 'Magenta', + 'Yellow', + 'Blue', + 'Red', + 'Green', + 'White' + ] + }, + '3d': [str(rgb) for rgb in range(0x00, 0xFF + 1)] + } } } @@ -148,6 +184,7 @@ 'Front LED1', 'Front LED2', 'Front LED3', + 'RGB Header' ] } @@ -172,11 +209,11 @@ }, { 'Control Item': 'Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] } ] @@ -196,11 +233,11 @@ }, { 'Control Item': 'Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Behavior', @@ -239,11 +276,11 @@ }, { 'Control Item': 'Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] } ] @@ -266,11 +303,11 @@ }, { 'Control Item': 'S0 Indicator Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'S0 Indicator Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'S3 Indicator Brightness', @@ -290,11 +327,11 @@ }, { 'Control Item': 'S3 Indicator Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'S3 Indicator Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Modern Standby Indicator Brightness', @@ -314,11 +351,11 @@ }, { 'Control Item': 'Modern Standby Indicator Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Modern Standby Indicator Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'S5 Indicator Brightness', @@ -338,11 +375,11 @@ }, { 'Control Item': 'S5 Indicator Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'S5 Indicator Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] } ] @@ -384,11 +421,11 @@ }, { 'Control Item': 'Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] } ] @@ -414,11 +451,11 @@ }, { 'Control Item': 'Color 2', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] }, { 'Control Item': 'Color 3', - 'Options': LED_COLOR['new']['RGB-color'] + 'Options': LED_COLOR['new']['RGB-color']['3d'] } ] @@ -531,6 +568,11 @@ None ] +QUIRKS_AVAILABLE = [ + 'NUC7_FREQUENCY_DEFAULT', + 'NUC10_RETURN_VALUE' +] + # Return value of FF FF FF FF is specific to the driver, not the actual WMI implementation. # Some of these return errors are the generic NUC WMI errors, not all are specific to the NUC LEDs. RETURN_ERROR = { @@ -538,9 +580,9 @@ 0xE2: 'Error (Undefined device)', 0xE3: 'Error (EC doesn\'t respond)', 0xE4: 'Error (Invalid Parameter)', - 0xE5: 'Error (Node busy. Command could not be executed because ' + + 0xE5: 'Error (Node busy. Command could not be executed because ' + \ 'command processing resources are temporarily unavailable.)', - 0xE6: 'Error (Command execution failure. ' + + 0xE6: 'Error (Command execution failure. ' + \ 'Parameter is illegal because destination device has been disabled or is unavailable)', 0xE7: 'Error (Invalid CEC Opcode)', 0xE8: 'Error (Data Buffer size is not enough)', @@ -549,4 +591,7 @@ } class NucWmiError(Exception): - pass + """ + NUC WMI error exception type. + """ + pass # pylint: disable=unnecessary-pass diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/get_led.py b/contrib/nuc_wmi/python/nuc_wmi/cli/get_led.py index 68d6982..81fd4d0 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/get_led.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/get_led.py @@ -4,13 +4,16 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_FILE, LED_COLOR, LED_COLOR_TYPE, LED_BLINK_FREQUENCY, LED_TYPE from nuc_wmi.get_led import get_led +import nuc_wmi + def get_led_cli(cli_args=None): """ Creates a CLI interface on top of the `nuc_wmi.get_led` `get_led` function. @@ -39,6 +42,20 @@ def get_led_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=[led for led in LED_TYPE['legacy'] if led], @@ -48,7 +65,18 @@ def get_led_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - (brightness, frequency, color) = get_led(LED_TYPE['legacy'].index(args.led), control_file=args.control_file) + led_color_type = LED_COLOR_TYPE['legacy'][args.led] + led_type_index = LED_TYPE['legacy'].index(args.led) + + (brightness, frequency_index, color_index) = get_led( # pylint: disable=unbalanced-tuple-unpacking + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + led_color = LED_COLOR['legacy'][led_color_type][color_index] + led_frequency = LED_BLINK_FREQUENCY['legacy'][frequency_index] print( dumps( @@ -56,13 +84,13 @@ def get_led_cli(cli_args=None): 'led': { 'type': args.led, 'brightness': str(brightness), - 'frequency': LED_BLINK_FREQUENCY['legacy'][frequency], - 'color': LED_COLOR['legacy'][LED_COLOR_TYPE['legacy'][args.led]][color] + 'frequency': led_frequency, + 'color': led_color } } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/get_led_new.py b/contrib/nuc_wmi/python/nuc_wmi/cli/get_led_new.py index 24aeb46..36d40a7 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/get_led_new.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/get_led_new.py @@ -4,15 +4,21 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_ITEM, CONTROL_FILE, LED_COLOR, LED_COLOR_TYPE, LED_INDICATOR_OPTION, LED_TYPE from nuc_wmi.get_led_new import get_led_control_item, get_led_indicator_option -from nuc_wmi.query_led import query_led_color_type, query_led_indicator_options +from nuc_wmi.query_led import query_led_color_type, query_led_control_items, query_led_indicator_options + +import nuc_wmi + +RGB_COLOR_1D = LED_COLOR['new']['RGB-color']['1d'] +RGB_COLOR_3D = LED_COLOR['new']['RGB-color']['3d'] -def get_led_control_item_cli(cli_args=None): +def get_led_control_item_cli(cli_args=None): # pylint: disable=too-many-branches,too-many-locals,too-many-statements """ Creates a CLI interface on top of the `nuc_wmi.get_led_new` `get_led_control_item` function. @@ -57,6 +63,20 @@ def get_led_control_item_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -76,22 +96,30 @@ def get_led_control_item_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) + led_type_index = LED_TYPE['new'].index(args.led) + available_indicator_options = query_led_indicator_options( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) - led_color_type = query_led_color_type( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + led_color_type_index = query_led_color_type( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) - indicator = LED_INDICATOR_OPTION.index(args.led_indicator_option) + led_color_type = LED_COLOR_TYPE['new'][led_color_type_index] - if indicator not in available_indicator_options: + led_indicator_option_index = LED_INDICATOR_OPTION.index(args.led_indicator_option) + + if led_indicator_option_index not in available_indicator_options: raise ValueError('Invalid indicator option for the selected LED') - control_items = CONTROL_ITEM[indicator][led_color_type] + control_items = CONTROL_ITEM[led_indicator_option_index][led_color_type_index] if control_items is None: raise ValueError('No control items are available for the selected LED and indicator option') @@ -106,15 +134,41 @@ def get_led_control_item_cli(cli_args=None): raise ValueError('Invalid control item specified for the selected LED and indicator option') control_item_value = get_led_control_item( - LED_TYPE['new'].index(args.led), - indicator, + led_type_index, + led_indicator_option_index, control_item_index, - control_file=args.control_file + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) # Convert the control item value index into its value if control_items[control_item_index]['Options'] == LED_COLOR['new']: - control_item_value = control_items[control_item_index]['Options'][LED_COLOR_TYPE['new'][led_color_type]][control_item_value] + if led_color_type == 'RGB-color': + color_dimensions = '1d' + + available_control_item_indexes = query_led_control_items( + led_type_index, + led_indicator_option_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + for control_item_index2 in available_control_item_indexes: + if control_items[control_item_index2]['Options'] == RGB_COLOR_3D: + color_dimensions = '3d' + + break + + if color_dimensions == '1d': + led_colors = RGB_COLOR_1D[args.led] + else: + led_colors = RGB_COLOR_3D + + control_item_value = led_colors[control_item_value] + else: + control_item_value = LED_COLOR['new'][led_color_type][control_item_value] else: control_item_value = control_items[control_item_index]['Options'][control_item_value] @@ -130,10 +184,10 @@ def get_led_control_item_cli(cli_args=None): } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) def get_led_indicator_option_cli(cli_args=None): @@ -164,6 +218,20 @@ def get_led_indicator_option_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -173,19 +241,28 @@ def get_led_indicator_option_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - indicator_option = get_led_indicator_option(LED_TYPE['new'].index(args.led), control_file=args.control_file) + led_type_index = LED_TYPE['new'].index(args.led) + + led_indicator_option_index = get_led_indicator_option( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + led_indicator_option = LED_INDICATOR_OPTION[led_indicator_option_index] print( dumps( { 'led': { 'type': args.led, - 'indicator_option': LED_INDICATOR_OPTION[indicator_option] + 'indicator_option': led_indicator_option } } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/led_app_notification.py b/contrib/nuc_wmi/python/nuc_wmi/cli/led_app_notification.py index beb0f25..2a9227c 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/led_app_notification.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/led_app_notification.py @@ -4,13 +4,16 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_FILE from nuc_wmi.led_app_notification import save_led_config +import nuc_wmi + def save_led_config_cli(cli_args=None): """ Send a save LED configuration LED app notification. @@ -37,11 +40,29 @@ def save_led_config_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) try: args = parser.parse_args(args=cli_args) - save_led_config(control_file=args.control_file) + save_led_config( + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) print( dumps( @@ -52,7 +73,7 @@ def save_led_config_cli(cli_args=None): } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/query_led.py b/contrib/nuc_wmi/python/nuc_wmi/cli/query_led.py index e1ad0a9..c43bf7e 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/query_led.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/query_led.py @@ -4,13 +4,17 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_ITEM, CONTROL_FILE, LED_COLOR_TYPE, LED_INDICATOR_OPTION, LED_TYPE from nuc_wmi.query_led import query_led_color_type, query_led_control_items, query_led_indicator_options, query_leds +import nuc_wmi + + def query_led_color_type_cli(cli_args=None): """ Creates a CLI interface on top of the `nuc_wmi.query_led` `query_led_color_type` function. @@ -39,6 +43,20 @@ def query_led_color_type_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -48,22 +66,31 @@ def query_led_color_type_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - led_color_type = query_led_color_type(LED_TYPE['new'].index(args.led), control_file=args.control_file) + led_type_index = LED_TYPE['new'].index(args.led) + + led_color_type_index = query_led_color_type( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + led_color_type = LED_COLOR_TYPE['new'][led_color_type_index] print( dumps( { 'led': { 'type': args.led, - 'color_type': LED_COLOR_TYPE['new'][led_color_type] + 'color_type': led_color_type } } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) def query_led_control_items_cli(cli_args=None): @@ -96,6 +123,20 @@ def query_led_control_items_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -110,43 +151,55 @@ def query_led_control_items_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - led_color_type = query_led_color_type( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + led_type_index = LED_TYPE['new'].index(args.led) + + led_color_type_index = query_led_color_type( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) - available_indicator_options = query_led_indicator_options( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + available_indicator_option_indexes = query_led_indicator_options( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) - indicator = LED_INDICATOR_OPTION.index(args.led_indicator_option) + led_indicator_option_index = LED_INDICATOR_OPTION.index(args.led_indicator_option) - if indicator not in available_indicator_options: + if led_indicator_option_index not in available_indicator_option_indexes: raise ValueError('Invalid indicator option for the selected LED') - control_items = query_led_control_items( - LED_TYPE['new'].index(args.led), - indicator, - control_file=args.control_file + available_control_item_indexes = query_led_control_items( + led_type_index, + led_indicator_option_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) + led_control_items = [ + CONTROL_ITEM[led_indicator_option_index][led_color_type_index][control_item_index]['Control Item'] \ + for control_item_index in available_control_item_indexes + ] + print( dumps( { 'led': { 'type': args.led, 'indicator_option': args.led_indicator_option, - 'control_items': [CONTROL_ITEM[indicator][led_color_type][control_item]['Control Item'] \ - for control_item in control_items] + 'control_items': led_control_items } } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) def query_led_indicator_options_cli(cli_args=None): @@ -177,6 +230,20 @@ def query_led_indicator_options_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -186,25 +253,34 @@ def query_led_indicator_options_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - led_indicator_options = query_led_indicator_options( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + led_type_index = LED_TYPE['new'].index(args.led) + + available_indicator_option_indexes = query_led_indicator_options( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) + led_indicator_options = [ + LED_INDICATOR_OPTION[led_indicator_option_index] \ + for led_indicator_option_index in available_indicator_option_indexes + ] + print( dumps( { 'led': { 'type': args.led, - 'indicator_options': [LED_INDICATOR_OPTION[indicator] for indicator in led_indicator_options] + 'indicator_options': led_indicator_options } } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) def query_leds_cli(cli_args=None): @@ -233,20 +309,40 @@ def query_leds_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) try: args = parser.parse_args(args=cli_args) - leds = query_leds(control_file=args.control_file) + available_led_type_indexes = query_leds( + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + led_types = [LED_TYPE['new'][led_type_index] for led_type_index in available_led_type_indexes] print( dumps( { - 'leds': [LED_TYPE['new'][led] for led in leds] + 'leds': led_types } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/set_led.py b/contrib/nuc_wmi/python/nuc_wmi/cli/set_led.py index f8358a2..c657066 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/set_led.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/set_led.py @@ -4,13 +4,16 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_FILE, LED_BRIGHTNESS, LED_COLOR, LED_COLOR_TYPE, LED_BLINK_FREQUENCY, LED_TYPE from nuc_wmi.set_led import set_led +import nuc_wmi + def set_led_cli(cli_args=None): """ Creates a CLI interface on top of the `nuc_wmi.set_led` `set_led` function. @@ -42,6 +45,20 @@ def set_led_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=[led for led in LED_TYPE['legacy'] if led], @@ -66,15 +83,24 @@ def set_led_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - led_type = LED_TYPE['legacy'].index(args.led) - frequency = LED_BLINK_FREQUENCY['legacy'].index(args.frequency) + led_color_type = LED_COLOR_TYPE['legacy'][args.led] + led_type_index = LED_TYPE['legacy'].index(args.led) + frequency_index = LED_BLINK_FREQUENCY['legacy'].index(args.frequency) try: - color = LED_COLOR['legacy'][LED_COLOR_TYPE['legacy'][args.led]].index(args.color) + color_index = LED_COLOR['legacy'][led_color_type].index(args.color) except ValueError as err: raise ValueError('Invalid color for the specified legacy LED') - set_led(led_type, args.brightness, frequency, color, control_file=args.control_file) + set_led( + led_type_index, + args.brightness, + frequency_index, + color_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) print( dumps( @@ -88,7 +114,7 @@ def set_led_cli(cli_args=None): } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_control_item.py b/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_control_item.py index 8ad99fc..b13f82e 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_control_item.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_control_item.py @@ -4,15 +4,22 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit -from nuc_wmi import CONTROL_ITEM, CONTROL_FILE, LED_COLOR, LED_COLOR_TYPE, LED_INDICATOR_OPTION, LED_TYPE -from nuc_wmi.query_led import query_led_color_type, query_led_indicator_options +from nuc_wmi import CONTROL_ITEM, CONTROL_FILE, LED_COLOR, LED_BLINK_FREQUENCY, LED_COLOR_TYPE +from nuc_wmi import LED_INDICATOR_OPTION, LED_TYPE +from nuc_wmi.query_led import query_led_color_type, query_led_control_items, query_led_indicator_options from nuc_wmi.set_led_control_item import set_led_control_item -def set_led_control_item_cli(cli_args=None): +import nuc_wmi + +RGB_COLOR_1D = LED_COLOR['new']['RGB-color']['1d'] +RGB_COLOR_3D = LED_COLOR['new']['RGB-color']['3d'] + +def set_led_control_item_cli(cli_args=None): # pylint: disable=too-many-branches,too-many-locals,too-many-statements """ Creates a CLI interface on top of the `nuc_wmi.set_led_control` `set_led_control_item` function. @@ -48,11 +55,17 @@ def set_led_control_item_cli(cli_args=None): for control_item in control_items: control_item_labels.append(control_item['Control Item']) - if control_item['Options'] is not None and control_item['Options'] != LED_COLOR['new']: + if control_item['Options'] is not None and \ + control_item['Options'] != LED_COLOR['new'] and \ + control_item['Options'] != LED_BLINK_FREQUENCY['new']: control_item_values.extend(control_item['Options']) + control_item_values.extend(filter(None, LED_BLINK_FREQUENCY['new'])) control_item_values.extend(LED_COLOR['new']['Dual-color Blue / Amber']) control_item_values.extend(LED_COLOR['new']['Dual-color Blue / White']) + control_item_values.extend(filter(None, LED_COLOR['new']['RGB-color']['1d']['HDD LED'])) + control_item_values.extend(filter(None, LED_COLOR['new']['RGB-color']['1d']['RGB Header'])) + control_item_values.extend(LED_COLOR['new']['RGB-color']['3d']) parser = ArgumentParser( description='Set the control item value for the control item of the indicator option ' + \ @@ -65,6 +78,20 @@ def set_led_control_item_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -86,25 +113,33 @@ def set_led_control_item_cli(cli_args=None): help='The control item value for the control item for the LED indicator option that is being set.' ) - try: + try: # pylint: disable=too-many-nested-blocks args = parser.parse_args(args=cli_args) - available_indicator_options = query_led_indicator_options( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + led_type_index = LED_TYPE['new'].index(args.led) + + available_indicator_option_indexes = query_led_indicator_options( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) - led_color_type = query_led_color_type( - LED_TYPE['new'].index(args.led), - control_file=args.control_file + led_color_type_index = query_led_color_type( + led_type_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) - indicator = LED_INDICATOR_OPTION.index(args.led_indicator_option) + led_color_type = LED_COLOR_TYPE['new'][led_color_type_index] - if indicator not in available_indicator_options: + led_indicator_option_index = LED_INDICATOR_OPTION.index(args.led_indicator_option) + + if led_indicator_option_index not in available_indicator_option_indexes: raise ValueError('Invalid indicator option for the selected LED') - control_items = CONTROL_ITEM[indicator][led_color_type] + control_items = CONTROL_ITEM[led_indicator_option_index][led_color_type_index] if control_items is None: raise ValueError('No control items are available for the selected LED and indicator option') @@ -121,18 +156,46 @@ def set_led_control_item_cli(cli_args=None): try: # Convert the control item value into its index if control_items[control_item_index]['Options'] == LED_COLOR['new']: - control_item_value_index = control_items[control_item_index]['Options'][LED_COLOR_TYPE['new'][led_color_type]].index(args.control_item_value) + if led_color_type == 'RGB-color': + color_dimensions = '1d' + + available_control_item_indexes = query_led_control_items( + led_type_index, + led_indicator_option_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + for control_item_index2 in available_control_item_indexes: + if control_items[control_item_index2]['Options'] == RGB_COLOR_3D: + color_dimensions = '3d' + + break + + if color_dimensions == '1d': + led_colors = RGB_COLOR_1D[args.led] + else: + led_colors = RGB_COLOR_3D + + control_item_value_index = led_colors.index(args.control_item_value) + else: + control_item_value_index = LED_COLOR['new'][led_color_type].index(args.control_item_value) else: control_item_value_index = control_items[control_item_index]['Options'].index(args.control_item_value) except ValueError as err: - raise ValueError('Invalid control item value for the specified control item') + raise ValueError( + 'Invalid control item value for the specified control item' + ) set_led_control_item( - LED_TYPE['new'].index(args.led), - indicator, + led_type_index, + led_indicator_option_index, control_item_index, control_item_value_index, - control_file=args.control_file + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) print( @@ -147,7 +210,7 @@ def set_led_control_item_cli(cli_args=None): } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_indicator_option.py b/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_indicator_option.py index 769e94d..6c2f30b 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_indicator_option.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/set_led_indicator_option.py @@ -4,13 +4,16 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_FILE, LED_INDICATOR_OPTION, LED_TYPE from nuc_wmi.set_led_indicator_option import set_led_indicator_option +import nuc_wmi + def set_led_indicator_option_cli(cli_args=None): """ Creates a CLI interface on top of the `nuc_wmi.set_led_indicator_option` `set_led_indicator_option` function. @@ -40,6 +43,20 @@ def set_led_indicator_option_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led', choices=LED_TYPE['new'], @@ -54,10 +71,16 @@ def set_led_indicator_option_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) + led_type_index = LED_TYPE['new'].index(args.led) + + led_indicator_option_index = LED_INDICATOR_OPTION.index(args.led_indicator_option) + set_led_indicator_option( - LED_TYPE['new'].index(args.led), - LED_INDICATOR_OPTION.index(args.led_indicator_option), - control_file=args.control_file + led_type_index, + led_indicator_option_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks ) print( @@ -70,7 +93,7 @@ def set_led_indicator_option_cli(cli_args=None): } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/switch_led_type.py b/contrib/nuc_wmi/python/nuc_wmi/cli/switch_led_type.py index 65eeeb1..75bc546 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/switch_led_type.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/switch_led_type.py @@ -4,13 +4,16 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit -from nuc_wmi import CONTROL_FILE, LED_COLOR, LED_COLOR_TYPE, LED_BLINK_FREQUENCY, LED_TYPE +from nuc_wmi import CONTROL_FILE from nuc_wmi.switch_led_type import LED_COLOR_GROUP, switch_led_type +import nuc_wmi + def switch_led_type_cli(cli_args=None): """ Creates a CLI interface on top of the `nuc_wmi.switch_led_type` `switch_led_type` function. @@ -39,6 +42,20 @@ def switch_led_type_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) parser.add_argument( 'led_color_group', choices=LED_COLOR_GROUP, @@ -48,7 +65,14 @@ def switch_led_type_cli(cli_args=None): try: args = parser.parse_args(args=cli_args) - switch_led_type(LED_COLOR_GROUP.index(args.led_color_group), control_file=args.control_file) + led_color_group_index = LED_COLOR_GROUP.index(args.led_color_group) + + switch_led_type( + led_color_group_index, + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) print( dumps( @@ -59,7 +83,7 @@ def switch_led_type_cli(cli_args=None): } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/cli/version.py b/contrib/nuc_wmi/python/nuc_wmi/cli/version.py index e16d956..a67a619 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/cli/version.py +++ b/contrib/nuc_wmi/python/nuc_wmi/cli/version.py @@ -4,13 +4,16 @@ from __future__ import print_function +import sys + from argparse import ArgumentParser from json import dumps -from sys import exit from nuc_wmi import CONTROL_FILE from nuc_wmi.version import wmi_interface_spec_compliance_version +import nuc_wmi + def wmi_interface_spec_compliance_version_cli(cli_args=None): """ Creates a CLI interface on top of the `nuc_wmi.version` `wmi_interface_spec_compliance_version` function. @@ -37,23 +40,43 @@ def wmi_interface_spec_compliance_version_cli(cli_args=None): default=None, help='The path to the NUC WMI control file. Defaults to ' + CONTROL_FILE + ' if not specified.' ) + parser.add_argument( + '-d', + '--debug', + action='store_true', + help='Enable debug logging of read and write to the NUC LED control file to stderr.' + ) + parser.add_argument( + '-q', + '--quirks', + action='append', + choices=nuc_wmi.QUIRKS_AVAILABLE, + default=None, + help='Enable NUC WMI quirks to work around various implementation issues or bugs.' + ) try: args = parser.parse_args(args=cli_args) - wmi_version = wmi_interface_spec_compliance_version(control_file=args.control_file) + wmi_version = wmi_interface_spec_compliance_version( + control_file=args.control_file, + debug=args.debug, + quirks=args.quirks + ) + + wmi_semver = '.'.join([str(semver_component) for semver_component in wmi_version]) print( dumps( { 'version': { 'type': 'wmi_interface_spec_compliance', - 'semver': '.'.join([str(semver_component) for semver_component in wmi_version]) + 'semver': wmi_semver } } ) ) - except Exception as err: + except Exception as err: # pylint: disable=broad-except print(dumps({'error': str(err)})) - exit(1) + sys.exit(1) diff --git a/contrib/nuc_wmi/python/nuc_wmi/control_file.py b/contrib/nuc_wmi/python/nuc_wmi/control_file.py index 20203a8..e0e85af 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/control_file.py +++ b/contrib/nuc_wmi/python/nuc_wmi/control_file.py @@ -2,14 +2,20 @@ `nuc_wmi.control_file` module provides interfaces for interacting with Intel NUC LED kernel module control file. """ +from __future__ import print_function + +import sys + from nuc_wmi import CONTROL_FILE, NucWmiError -def read_control_file(control_file=None): +def read_control_file(control_file=None, debug=False, quirks=None): # pylint: disable=unused-argument """ Read the NUC LED control file hex bytes string. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises normal `IOError`/`OSError` on failure to read the control file, or `ValueError` for hex conversion error. Returns: @@ -22,6 +28,9 @@ def read_control_file(control_file=None): # Remove the new line and null char the driver leaves raw_hex_byte_string = raw_hex_byte_string.rstrip("\x00").rstrip("\n") + if debug: + print('r: ', raw_hex_byte_string, file=sys.stderr) + byte_list = [int(hex_byte_str, 16) for hex_byte_str in raw_hex_byte_string.split(' ')] for hex_byte in byte_list: @@ -34,14 +43,16 @@ def read_control_file(control_file=None): return tuple(byte_list) -def write_control_file(int_byte_list, control_file=None): +def write_control_file(int_byte_list, control_file=None, debug=False, quirks=None): # pylint: disable=unused-argument """ Converts the integer byte list into a hex byte string and writes it to the NUC control file. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. int_byte_list: List of integers bytes to be converted into a hex byte string to send to the NUC control file. May be int byte strings. Integers must be 0-255. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises normal `IOError`/`OSError` on failure to read the control file, `ValueError` for hex conversion error, or `nuc_wmi.NucWmiError` for input value errors. @@ -52,8 +63,11 @@ def write_control_file(int_byte_list, control_file=None): raise NucWmiError('Error (NUC LED byte values must be 0-255)') raw_hex_byte_string = ' '.join( - ['{:02x}'.format(int(int_byte)) for int_byte in (int_byte_list + ([0] * (5 - len(int_byte_list))))] + ['{:02x}'.format(int(int_byte)) for int_byte in int_byte_list + ([0] * (5 - len(int_byte_list)))] ) + if debug: + print('w: ', raw_hex_byte_string, file=sys.stderr) + with open(control_file or CONTROL_FILE, 'w') as fout: fout.write(raw_hex_byte_string) diff --git a/contrib/nuc_wmi/python/nuc_wmi/get_led.py b/contrib/nuc_wmi/python/nuc_wmi/get_led.py index 513d9e4..e95d044 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/get_led.py +++ b/contrib/nuc_wmi/python/nuc_wmi/get_led.py @@ -5,34 +5,42 @@ from nuc_wmi import NucWmiError, RETURN_ERROR from nuc_wmi.control_file import read_control_file, write_control_file -METHOD_ID=0x01 +METHOD_ID = 0x01 -def get_led(led, control_file=None): +def get_led(led, control_file=None, debug=False, quirks=None): """ Get legacy LED state with regard to brightness, frequency, and color. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led: Selects the legacy LED to get the state for. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. Returns: - Tuple of legacy brightness, frequency, and color of the select LED. + Tuple of legacy brightness, frequency, and color indexes of the select LED. """ get_led_byte_list = [METHOD_ID, led] - write_control_file(get_led_byte_list, control_file=control_file) + write_control_file(get_led_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, brightness, frequency, color - ) = read_control_file(control_file=control_file) + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) + # On a factory fresh NUC 7, the BIOS can return a default frequency value of 0 which + # is not a valid enum range value and this causes the frequency value to be returned as + # null due to how we implemented the enums. + if quirks is not None and 'NUC7_FREQUENCY_DEFAULT' in quirks and frequency == 0: + frequency = 0x01 + return tuple([brightness, frequency, color]) diff --git a/contrib/nuc_wmi/python/nuc_wmi/get_led_new.py b/contrib/nuc_wmi/python/nuc_wmi/get_led_new.py index d4efbc3..275ad5c 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/get_led_new.py +++ b/contrib/nuc_wmi/python/nuc_wmi/get_led_new.py @@ -4,23 +4,33 @@ from nuc_wmi import NucWmiError, RETURN_ERROR from nuc_wmi.control_file import read_control_file, write_control_file +from nuc_wmi.utils import byte_list_to_bitmap GET_LED_TYPE = [ 'get_led_indicator_option', 'get_led_control_item' ] -METHOD_ID=0x04 +METHOD_ID = 0x04 -def get_led_control_item(led_type, led_indicator_option, control_item, control_file=None): +def get_led_control_item( # pylint: disable=too-many-arguments + led_type, + led_indicator_option, + control_item, + control_file=None, + debug=False, + quirks=None +): """ Get the current control item value for the control item of the indicator option for the specified LED type. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. control_item: The control item of the specified LED type indicator option for which to retrieve the value. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_indicator_option: The indicator option for the specified LED type for which to retrieve the current control item value. led_type: The LED type for which to retrieve the current control item. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -36,14 +46,14 @@ def get_led_control_item(led_type, led_indicator_option, control_item, control_f control_item ] - write_control_file(get_led_control_item_byte_list, control_file=control_file) + write_control_file(get_led_control_item_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, control_item_value, - reserved_byte_1, - reserved_byte_2 - ) = read_control_file(control_file=control_file) + reserved_byte_1, # pylint: disable=unused-variable + reserved_byte_2 # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) @@ -51,13 +61,16 @@ def get_led_control_item(led_type, led_indicator_option, control_item, control_f return control_item_value -def get_led_indicator_option(led_type, control_file=None): +def get_led_indicator_option(led_type, control_file=None, debug=False, quirks=None): """ Get the current indicator option for the LED type. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_type: The LED type for which to retrieve the current indicator option. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. + Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -71,16 +84,22 @@ def get_led_indicator_option(led_type, control_file=None): led_type ] - write_control_file(get_led_indicator_option_byte_list, control_file=control_file) + write_control_file(get_led_indicator_option_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, led_indicator_option, - reserved_byte_1, - reserved_byte_2 - ) = read_control_file(control_file=control_file) + reserved_byte_1, # pylint: disable=unused-variable + reserved_byte_2 # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR[error_code]) - return led_indicator_option + if quirks is not None and 'NUC10_RETURN_VALUE' in quirks: + return led_indicator_option + + led_indicator_option_bitmaps = [led_indicator_option] + led_indicator_option_bitmap = byte_list_to_bitmap(led_indicator_option_bitmaps)[::-1] + + return led_indicator_option_bitmap.index('1') diff --git a/contrib/nuc_wmi/python/nuc_wmi/led_app_notification.py b/contrib/nuc_wmi/python/nuc_wmi/led_app_notification.py index f491c9a..32173eb 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/led_app_notification.py +++ b/contrib/nuc_wmi/python/nuc_wmi/led_app_notification.py @@ -5,19 +5,21 @@ from nuc_wmi import NucWmiError, RETURN_ERROR from nuc_wmi.control_file import read_control_file, write_control_file -METHOD_ID=0x07 +METHOD_ID = 0x07 NOTIFICATION_TYPE = [ None, 'save_led_config' ] -def save_led_config(control_file=None): +def save_led_config(control_file=None, debug=False, quirks=None): """ Send a save LED configuration LED app notification. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -28,14 +30,14 @@ def save_led_config(control_file=None): NOTIFICATION_TYPE.index('save_led_config') ] - write_control_file(notification_byte_list, control_file=control_file) + write_control_file(notification_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, - reserved_byte_1, - reserved_byte_2, - reserved_byte_3 - ) = read_control_file(control_file=control_file) + reserved_byte_1, # pylint: disable=unused-variable + reserved_byte_2, # pylint: disable=unused-variable + reserved_byte_3 # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/nuc_wmi/query_led.py b/contrib/nuc_wmi/python/nuc_wmi/query_led.py index d1197a3..df982c6 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/query_led.py +++ b/contrib/nuc_wmi/python/nuc_wmi/query_led.py @@ -2,12 +2,12 @@ `nuc_wmi.query_led` provides an interface to the WMI query led set of functions. """ -from nuc_wmi import CONTROL_ITEM, LED_COLOR_TYPE, LED_INDICATOR_OPTION, LED_TYPE, NucWmiError, RETURN_ERROR +from nuc_wmi import CONTROL_ITEM, LED_INDICATOR_OPTION, LED_TYPE, NucWmiError, RETURN_ERROR from nuc_wmi.control_file import read_control_file, write_control_file from nuc_wmi.utils import byte_list_to_bitmap LED_INDICATOR_OPTION_DISABLED = 0x06 -METHOD_ID=0x03 +METHOD_ID = 0x03 QUERY_TYPE = [ 'query_leds', @@ -16,13 +16,15 @@ 'query_led_control_items' ] -def query_led_color_type(led_type, control_file=None): +def query_led_color_type(led_type, control_file=None, debug=False, quirks=None): """ Query the LED color type for the LED type. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_type: The LED type for which to query the LED color type. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -32,7 +34,7 @@ def query_led_color_type(led_type, control_file=None): query_led_color_byte_list = [METHOD_ID, QUERY_TYPE.index('query_led_color_type'), led_type] - write_control_file(query_led_color_byte_list, control_file=control_file) + write_control_file(query_led_color_byte_list, control_file=control_file, debug=debug, quirks=quirks) # Bitmap [0:7], [8:15], [16:23] ( @@ -40,7 +42,7 @@ def query_led_color_type(led_type, control_file=None): led_color_type_bitmap_1, led_color_type_bitmap_2, led_color_type_bitmap_3 - ) = read_control_file(control_file=control_file) + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) @@ -50,19 +52,27 @@ def query_led_color_type(led_type, control_file=None): led_color_type_bitmap_2, led_color_type_bitmap_1 ] - led_color_type_bitmap = byte_list_to_bitmap(led_color_type_bitmaps) - return int(led_color_type_bitmap, 2) + if quirks is not None and 'NUC10_RETURN_VALUE' in quirks: + led_color_type_bitmap = byte_list_to_bitmap(led_color_type_bitmaps) + return int(led_color_type_bitmap, 2) -def query_led_control_items(led_type, led_indicator_option, control_file=None): + led_color_type_bitmap = byte_list_to_bitmap(led_color_type_bitmaps)[::-1] + + return led_color_type_bitmap.index('1') + + +def query_led_control_items(led_type, led_indicator_option, control_file=None, debug=False, quirks=None): """ Query the LED control items for the LED indicator option of the LED type. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_indicator_option: The LED indicator option to use for the LED type when querying for the LED control items. led_type: The LED type for which to query the LED control items. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -70,7 +80,7 @@ def query_led_control_items(led_type, led_indicator_option, control_file=None): List of available `nuc_wmi.CONTROL_ITEM` indexes for the specified LED type and LED indicator option. """ - led_color_type = query_led_color_type(led_type, control_file=control_file) + led_color_type = query_led_color_type(led_type, control_file=control_file, debug=debug, quirks=quirks) query_led_control_item_byte_list = [ METHOD_ID, @@ -79,7 +89,7 @@ def query_led_control_items(led_type, led_indicator_option, control_file=None): led_indicator_option ] - write_control_file(query_led_control_item_byte_list, control_file=control_file) + write_control_file(query_led_control_item_byte_list, control_file=control_file, debug=debug, quirks=quirks) # Bitmap [0:7], [8:15], [16:23] ( @@ -87,7 +97,7 @@ def query_led_control_items(led_type, led_indicator_option, control_file=None): led_control_item_bitmap_1, led_control_item_bitmap_2, led_control_item_bitmap_3 - ) = read_control_file(control_file=control_file) + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) @@ -107,13 +117,15 @@ def query_led_control_items(led_type, led_indicator_option, control_file=None): index < len(CONTROL_ITEM[led_indicator_option][led_color_type])] -def query_led_indicator_options(led_type, control_file=None): +def query_led_indicator_options(led_type, control_file=None, debug=False, quirks=None): """ Query the LED indicator options available for the LED type. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_type: The LED type for which to query the LED indicator options. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -127,7 +139,7 @@ def query_led_indicator_options(led_type, control_file=None): led_type ] - write_control_file(query_led_indicator_options_byte_list, control_file=control_file) + write_control_file(query_led_indicator_options_byte_list, control_file=control_file, debug=debug, quirks=quirks) # Bitmap [0:7], [8:15], [16:23] ( @@ -135,7 +147,7 @@ def query_led_indicator_options(led_type, control_file=None): led_indicator_option_bitmap_1, led_indicator_option_bitmap_2, led_indicator_option_bitmap_3 - ) = read_control_file(control_file=control_file) + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) @@ -151,12 +163,14 @@ def query_led_indicator_options(led_type, control_file=None): index < len(LED_INDICATOR_OPTION)] -def query_leds(control_file=None): +def query_leds(control_file=None, debug=False, quirks=None): """ List all LED types supported. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -166,7 +180,7 @@ def query_leds(control_file=None): query_leds_byte_list = [METHOD_ID, QUERY_TYPE.index('query_leds')] - write_control_file(query_leds_byte_list, control_file=control_file) + write_control_file(query_leds_byte_list, control_file=control_file, debug=debug, quirks=quirks) # Bitmap [0:7], [8:15], [16:23] ( @@ -174,7 +188,7 @@ def query_leds(control_file=None): led_type_bitmap_1, led_type_bitmap_2, led_type_bitmap_3 - ) = read_control_file(control_file=control_file) + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/nuc_wmi/set_led.py b/contrib/nuc_wmi/python/nuc_wmi/set_led.py index 803c42f..324e0f4 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/set_led.py +++ b/contrib/nuc_wmi/python/nuc_wmi/set_led.py @@ -5,9 +5,17 @@ from nuc_wmi import NucWmiError, RETURN_ERROR from nuc_wmi.control_file import read_control_file, write_control_file -METHOD_ID=0x02 - -def set_led(led, brightness, frequency, color, control_file=None): +METHOD_ID = 0x02 + +def set_led( # pylint: disable=too-many-arguments + led, + brightness, + frequency, + color, + control_file=None, + debug=False, + quirks=None +): """ Set LED state with regard to brightness, frequency, and color. @@ -15,8 +23,10 @@ def set_led(led, brightness, frequency, color, control_file=None): brightness: Controls the brightness level of the LED. color: Sets legacy RGB-color for LED. control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. frequency: Sets the legacy LED frequency. led: Selects the legacy LED to set a state for. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -24,14 +34,14 @@ def set_led(led, brightness, frequency, color, control_file=None): set_led_byte_list = [METHOD_ID, led, brightness, frequency, color] - write_control_file(set_led_byte_list, control_file=control_file) + write_control_file(set_led_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( brightness_error, frequency_error, color_error, - reserved_byte - ) = read_control_file(control_file=control_file) + reserved_byte # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if brightness_error > 0: raise NucWmiError(RETURN_ERROR.get(brightness_error, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/nuc_wmi/set_led_control_item.py b/contrib/nuc_wmi/python/nuc_wmi/set_led_control_item.py index 1812820..0688005 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/set_led_control_item.py +++ b/contrib/nuc_wmi/python/nuc_wmi/set_led_control_item.py @@ -7,7 +7,15 @@ METHOD_ID = 0x06 -def set_led_control_item(led_type, led_indicator_option, control_item, control_item_value, control_file=None): +def set_led_control_item( # pylint: disable=too-many-arguments + led_type, + led_indicator_option, + control_item, + control_item_value, + control_file=None, + debug=False, + quirks=None +): """ Set the control item for the LED indicator option for the specified LED type, @@ -15,8 +23,10 @@ def set_led_control_item(led_type, led_indicator_option, control_item, control_i control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. control_item: The control item to set the value for. control_item_value: The value for the control item to set. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_indicator_option: The LED indicator option of the LED type for which to set the control item. led_type: The LED type for which to set the control item. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -24,14 +34,14 @@ def set_led_control_item(led_type, led_indicator_option, control_item, control_i set_led_control_item_byte_list = [METHOD_ID, led_type, led_indicator_option, control_item, control_item_value] - write_control_file(set_led_control_item_byte_list, control_file=control_file) + write_control_file(set_led_control_item_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, - reserved_byte_1, - reserved_byte_2, - reserved_byte_3 - ) = read_control_file(control_file=control_file) + reserved_byte_1, # pylint: disable=unused-variable + reserved_byte_2, # pylint: disable=unused-variable + reserved_byte_3 # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/nuc_wmi/set_led_indicator_option.py b/contrib/nuc_wmi/python/nuc_wmi/set_led_indicator_option.py index 669fae6..2d3b021 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/set_led_indicator_option.py +++ b/contrib/nuc_wmi/python/nuc_wmi/set_led_indicator_option.py @@ -7,14 +7,16 @@ METHOD_ID = 0x05 -def set_led_indicator_option(led_type, led_indicator_option, control_file=None): +def set_led_indicator_option(led_type, led_indicator_option, control_file=None, debug=False, quirks=None): """ Set the LED indicator option for the specified LED type, Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_indicator_option: The LED indicator option to set for the LED type. led_type: The LED type for which to set the LED indicator option. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -22,14 +24,14 @@ def set_led_indicator_option(led_type, led_indicator_option, control_file=None): set_led_indicator_option_byte_list = [METHOD_ID, led_type, led_indicator_option] - write_control_file(set_led_indicator_option_byte_list, control_file=control_file) + write_control_file(set_led_indicator_option_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, - reserved_byte_1, - reserved_byte_2, - reserved_byte_3 - ) = read_control_file(control_file=control_file) + reserved_byte_1, # pylint: disable=unused-variable + reserved_byte_2, # pylint: disable=unused-variable + reserved_byte_3 # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/nuc_wmi/switch_led_type.py b/contrib/nuc_wmi/python/nuc_wmi/switch_led_type.py index f0e30eb..3a4d997 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/switch_led_type.py +++ b/contrib/nuc_wmi/python/nuc_wmi/switch_led_type.py @@ -10,14 +10,16 @@ 'Multi color LED' ] -METHOD_ID=0x08 +METHOD_ID = 0x08 -def switch_led_type(led_color_group, control_file=None): +def switch_led_type(led_color_group, control_file=None, debug=False, quirks=None): """ Switches the LED color group type. Args: + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. led_color_group: The LED color group type to set. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -25,14 +27,14 @@ def switch_led_type(led_color_group, control_file=None): switch_led_byte_list = [METHOD_ID, led_color_group] - write_control_file(switch_led_byte_list, control_file=control_file) + write_control_file(switch_led_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, - reserved_byte_1, - reserved_byte_2, - reserved_byte_3 - ) = read_control_file(control_file=control_file) + reserved_byte_1, # pylint: disable=unused-variable + reserved_byte_2, # pylint: disable=unused-variable + reserved_byte_3 # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/nuc_wmi/version.py b/contrib/nuc_wmi/python/nuc_wmi/version.py index 007dfe8..ecc85f9 100644 --- a/contrib/nuc_wmi/python/nuc_wmi/version.py +++ b/contrib/nuc_wmi/python/nuc_wmi/version.py @@ -5,18 +5,20 @@ from nuc_wmi import NucWmiError, RETURN_ERROR from nuc_wmi.control_file import read_control_file, write_control_file -METHOD_ID=0x09 +METHOD_ID = 0x09 VERSION_TYPE = [ 'wmi_interface_spec_compliance_version' ] -def wmi_interface_spec_compliance_version(control_file=None): +def wmi_interface_spec_compliance_version(control_file=None, debug=False, quirks=None): """ Returns the version for the WMI interface spec compliance. Args: control_file: Sets the control file to use if provided, otherwise `nuc_wmi.CONTROL_FILE` is used. + debug: Whether or not to enable debug logging of read and write to the NUC LED control file to stderr. + quirks: Enable NUC WMI quirks to work around various implementation issues or bugs. Exceptions: Raises `nuc_wmi.NucWmiError` exception if kernel module returns an error code, or if `read_control_file` or `write_control_file` raise an exception. @@ -29,14 +31,14 @@ def wmi_interface_spec_compliance_version(control_file=None): VERSION_TYPE.index('wmi_interface_spec_compliance_version') ] - write_control_file(wmi_version_byte_list, control_file=control_file) + write_control_file(wmi_version_byte_list, control_file=control_file, debug=debug, quirks=quirks) ( error_code, version_byte_1, version_byte_2, - reserved_byte - ) = read_control_file(control_file=control_file) + reserved_byte # pylint: disable=unused-variable + ) = read_control_file(control_file=control_file, debug=debug, quirks=quirks) if error_code > 0: raise NucWmiError(RETURN_ERROR.get(error_code, 'Error (Unknown NUC WMI error code)')) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_new_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_new_test.py index 3992efa..3c5f2cc 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_new_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_new_test.py @@ -11,10 +11,11 @@ import json import unittest -from mock import MagicMock, patch +from mock import patch -from nuc_wmi import CONTROL_ITEM, CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, LED_BRIGHTNESS_MULTI_COLOR -from nuc_wmi import LED_COLOR, LED_COLOR_TYPE, LED_INDICATOR_OPTION, LED_TYPE, NucWmiError +from nuc_wmi import CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR +from nuc_wmi import LED_BLINK_FREQUENCY, LED_BRIGHTNESS_MULTI_COLOR, LED_COLOR, LED_COLOR_TYPE, LED_INDICATOR_OPTION +from nuc_wmi import LED_TYPE, NucWmiError from nuc_wmi.cli.get_led_new import get_led_control_item_cli, get_led_indicator_option_cli import nuc_wmi @@ -40,18 +41,20 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.get_led_new.print') - @patch('nuc_wmi.cli.get_led_new.exit') + @patch('nuc_wmi.cli.get_led_new.sys.exit') @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') @patch('nuc_wmi.cli.get_led_new.get_led_control_item') - def test_get_led_control_item_cli( + def test_get_led_control_item_cli( # pylint: disable=too-many-arguments,too-many-statements self, nuc_wmi_get_led_control_item, nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, nuc_wmi_query_led_color_type, nuc_wmi_sys_exit, nuc_wmi_print @@ -62,17 +65,18 @@ def test_get_led_control_item_cli( self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.get_led_new.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that get_led_control_item_cli returns the proper JSON response and exit # code for valid cli args # Get HDD LED control item value of 37 for Brightness of HDD Activity Indicator - expected_brightness = 0x37 + expected_brightness = 37 nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] nuc_wmi_get_led_control_item.return_value = expected_brightness returned_get_led_control_item_cli = get_led_control_item_cli( [ @@ -84,12 +88,17 @@ def test_get_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_get_led_control_item.assert_called_with( LED_TYPE['new'].index('HDD LED'), @@ -100,7 +109,9 @@ def test_get_led_control_item_cli( 'Options': LED_BRIGHTNESS_MULTI_COLOR } ), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -117,17 +128,37 @@ def test_get_led_control_item_cli( self.assertEqual(returned_get_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_get_led_control_item.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli2( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that get_led_control_item_cli captures raised errors and returns # the proper JSON error response and exit code. nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] nuc_wmi_get_led_control_item.side_effect = NucWmiError('Error (Function not supported)') returned_get_led_control_item_cli = get_led_control_item_cli( [ @@ -139,12 +170,17 @@ def test_get_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_get_led_control_item.assert_called_with( LED_TYPE['new'].index('HDD LED'), @@ -155,25 +191,46 @@ def test_get_led_control_item_cli( 'Options': LED_BRIGHTNESS_MULTI_COLOR } ), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_get_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() - nuc_wmi_get_led_control_item = MagicMock() + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli3( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 3: Test that get_led_control_item_cli raises proper error when an invalid indicator # option for the current LED is chosen and returns he proper JSON error response and exit code. nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_get_led_control_item_cli = get_led_control_item_cli( [ LED_TYPE['new'][1], @@ -184,12 +241,17 @@ def test_get_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_get_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with('{"error": "Invalid indicator option for the selected LED"}') @@ -197,18 +259,38 @@ def test_get_led_control_item_cli( self.assertEqual(returned_get_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_get_led_control_item.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli4( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 4: Test that get_led_control_item_cli raises proper error when there are no control items for # for the current LED and indicator option chosen and returns he proper JSON error response and exit # code. nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Single-color LED') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04, 0x05] + nuc_wmi_query_led_indicator_options.return_value = [1, 4, 5] returned_get_led_control_item_cli = get_led_control_item_cli( [ LED_TYPE['new'][0], @@ -219,12 +301,17 @@ def test_get_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('Power Button LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('Power Button LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_get_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with( @@ -234,18 +321,38 @@ def test_get_led_control_item_cli( self.assertEqual(returned_get_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_get_led_control_item.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli5( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 5: Test that get_led_control_item_cli raises proper error when an invalid control item for # for the current LED and indicator option is chosen and returns he proper JSON error response and # exit code. nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_get_led_control_item_cli = get_led_control_item_cli( [ LED_TYPE['new'][1], @@ -256,12 +363,17 @@ def test_get_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_get_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with( @@ -273,14 +385,16 @@ def test_get_led_control_item_cli( @patch('nuc_wmi.cli.get_led_new.print') - @patch('nuc_wmi.cli.get_led_new.exit') + @patch('nuc_wmi.cli.get_led_new.sys.exit') @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') @patch('nuc_wmi.cli.get_led_new.get_led_control_item') - def test_get_led_control_item_cli2( + def test_get_led_control_item_cli6( # pylint: disable=too-many-arguments,too-many-statements self, nuc_wmi_get_led_control_item, nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, nuc_wmi_query_led_color_type, nuc_wmi_sys_exit, nuc_wmi_print @@ -291,16 +405,17 @@ def test_get_led_control_item_cli2( self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.get_led_new.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 6: Test getting control item that uses color # Get HDD LED control item color of White for Color of HDD Activity Indicator expected_color = LED_COLOR['new']['Dual-color Blue / White'].index('White') nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] nuc_wmi_get_led_control_item.return_value = expected_color returned_get_led_control_item_cli = get_led_control_item_cli( [ @@ -312,12 +427,17 @@ def test_get_led_control_item_cli2( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_get_led_control_item.assert_called_with( LED_TYPE['new'].index('HDD LED'), @@ -328,7 +448,9 @@ def test_get_led_control_item_cli2( 'Options': LED_COLOR['new'] } ), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -347,7 +469,457 @@ def test_get_led_control_item_cli2( @patch('nuc_wmi.cli.get_led_new.print') - @patch('nuc_wmi.cli.get_led_new.exit') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli7( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 7: Test getting control item that uses color + + # Get HDD LED control item color of Indigo for Color of HDD Activity Indicator with 1d RGB-color LED type + expected_color = LED_COLOR['new']['RGB-color']['1d']['HDD LED'].index('Indigo') + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 4] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + nuc_wmi_get_led_control_item.return_value = expected_color + returned_get_led_control_item_cli = get_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[1], + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_get_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[1], + 'control_item': CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['1d']['HDD LED'][expected_color] + } + } + ) + + self.assertEqual(returned_get_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli8( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 8: Test getting control item that uses color + + # Get HDD LED control item color of 100 for Color of HDD Activity Indicator with 3d RGB-color LED type + expected_color = LED_COLOR['new']['RGB-color']['3d'].index('100') + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3, 4] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + nuc_wmi_get_led_control_item.return_value = expected_color + returned_get_led_control_item_cli = get_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[1], + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_get_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[1], + 'control_item': CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['3d'][expected_color] + } + } + ) + + self.assertEqual(returned_get_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli9( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 9: Test getting control item that uses color + + # Get HDD LED control item color of Indigo for Color of Software Indicator with 1d RGB-color LED type + expected_color = LED_COLOR['new']['RGB-color']['1d']['HDD LED'].index('Indigo') + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + nuc_wmi_get_led_control_item.return_value = expected_color + returned_get_led_control_item_cli = get_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4], + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_get_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4], + 'control_item': CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['1d']['HDD LED'][expected_color] + } + } + ) + + self.assertEqual(returned_get_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli10( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 10: Test getting control item that uses color + + # Get HDD LED control item color of 100 for Color of Software Indicator with 3d RGB-color LED type + expected_color = LED_COLOR['new']['RGB-color']['3d'].index('100') + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3, 4, 5] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + nuc_wmi_get_led_control_item.return_value = expected_color + returned_get_led_control_item_cli = get_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4], + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_get_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4], + 'control_item': CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['3d'][expected_color] + } + } + ) + + self.assertEqual(returned_get_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.query_led_color_type') + @patch('nuc_wmi.cli.get_led_new.query_led_control_items') + @patch('nuc_wmi.cli.get_led_new.query_led_indicator_options') + @patch('nuc_wmi.cli.get_led_new.get_led_control_item') + def test_get_led_control_item_cli11( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_get_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_control_item is nuc_wmi_get_led_control_item) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.get_led_new.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 11: Test getting control item that uses blink frequency + + # Get HDD LED control item Blink Frequency of 1.0Hz for Blink Frequency of Software Indicator + # with 3d RGB-color LED type + expected_blinking_frequency = LED_BLINK_FREQUENCY['new'].index('1.0Hz') + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3, 4, 5] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + nuc_wmi_get_led_control_item.return_value = expected_blinking_frequency + returned_get_led_control_item_cli = get_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4], + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[2]['Control Item'] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_not_called() + + nuc_wmi_get_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Blinking Frequency', + 'Options': LED_BLINK_FREQUENCY['new'] + } + ), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4], + 'control_item': CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[2]['Control Item'], + 'control_item_value': LED_BLINK_FREQUENCY['new'][expected_blinking_frequency] + } + } + ) + + self.assertEqual(returned_get_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') @patch('nuc_wmi.cli.get_led_new.get_led_indicator_option') def test_get_led_indicator_option_cli( self, @@ -360,14 +932,14 @@ def test_get_led_indicator_option_cli( """ self.assertTrue(nuc_wmi.cli.get_led_new.get_led_indicator_option is nuc_wmi_get_led_indicator_option) - self.assertTrue(nuc_wmi.cli.get_led_new.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that get_led_indicator_option_cli returns the proper JSON response and exit # code for valid cli args # Get HDD LED indicator option of HDD Activity Indicator - expected_led_indicator = 0x01 + expected_led_indicator = 1 nuc_wmi_get_led_indicator_option.return_value = expected_led_indicator returned_get_led_indicator_option_cli = get_led_indicator_option_cli( [ @@ -377,7 +949,9 @@ def test_get_led_indicator_option_cli( nuc_wmi_get_led_indicator_option.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -392,10 +966,23 @@ def test_get_led_indicator_option_cli( self.assertEqual(returned_get_led_indicator_option_cli, None) - # Reset - nuc_wmi_get_led_indicator_option.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.get_led_indicator_option') + def test_get_led_indicator_option_cli2( + self, + nuc_wmi_get_led_indicator_option, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_indicator_option_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_indicator_option is nuc_wmi_get_led_indicator_option) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that get_led_indicator_option_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -409,9 +996,60 @@ def test_get_led_indicator_option_cli( nuc_wmi_get_led_indicator_option.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_get_led_indicator_option_cli, None) + + + @patch('nuc_wmi.cli.get_led_new.print') + @patch('nuc_wmi.cli.get_led_new.sys.exit') + @patch('nuc_wmi.cli.get_led_new.get_led_indicator_option') + def test_get_led_indicator_option_cli3( + self, + nuc_wmi_get_led_indicator_option, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_indicator_option_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led_new.get_led_indicator_option is nuc_wmi_get_led_indicator_option) + self.assertTrue(nuc_wmi.cli.get_led_new.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led_new.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 3: Test that get_led_indicator_option_cli returns the proper JSON response and exit + # code for valid cli args + + # Get HDD LED indicator option of Software Indicator + expected_led_indicator = 4 + nuc_wmi_get_led_indicator_option.return_value = expected_led_indicator + returned_get_led_indicator_option_cli = get_led_indicator_option_cli( + [ + LED_TYPE['new'][1] + ] + ) + + nuc_wmi_get_led_indicator_option.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[expected_led_indicator] + } + } + ) + + self.assertEqual(returned_get_led_indicator_option_cli, None) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_test.py index 5cee28d..3aedadb 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/get_led_test.py @@ -35,10 +35,10 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.get_led.print') - @patch('nuc_wmi.cli.get_led.exit') + @patch('nuc_wmi.cli.get_led.sys.exit') @patch('nuc_wmi.cli.get_led.get_led') def test_get_led_cli( self, @@ -51,8 +51,8 @@ def test_get_led_cli( """ self.assertTrue(nuc_wmi.cli.get_led.get_led is nuc_wmi_get_led) - self.assertTrue(nuc_wmi.cli.get_led.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.get_led.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.get_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that get_led_cli returns the proper JSON response and exit # code for valid cli args @@ -70,7 +70,9 @@ def test_get_led_cli( nuc_wmi_get_led.assert_called_with( LED_TYPE['legacy'].index('S0 Ring LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -87,16 +89,26 @@ def test_get_led_cli( self.assertEqual(returned_get_led_cli, None) - # Reset - nuc_wmi_get_led.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.get_led.print') + @patch('nuc_wmi.cli.get_led.sys.exit') + @patch('nuc_wmi.cli.get_led.get_led') + def test_get_led_cli2( + self, + nuc_wmi_get_led, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `get_led_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.get_led.get_led is nuc_wmi_get_led) + self.assertTrue(nuc_wmi.cli.get_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.get_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that get_led_cli captures raised errors and returns # the proper JSON error response and exit code. - expected_brightness = str(LED_BRIGHTNESS['legacy'].index('47')) - expected_frequency = LED_BLINK_FREQUENCY['legacy'].index('Always on') - expected_color = LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Cyan') nuc_wmi_get_led.side_effect = NucWmiError('Error (Function not supported)') returned_get_led_cli = get_led_cli( @@ -107,7 +119,9 @@ def test_get_led_cli( nuc_wmi_get_led.assert_called_with( LED_TYPE['legacy'].index('S0 Ring LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/led_app_notification_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/led_app_notification_test.py index f0636fe..1c84570 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/led_app_notification_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/led_app_notification_test.py @@ -35,10 +35,10 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.led_app_notification.print') - @patch('nuc_wmi.cli.led_app_notification.exit') + @patch('nuc_wmi.cli.led_app_notification.sys.exit') @patch('nuc_wmi.cli.led_app_notification.save_led_config') def test_save_led_config_cli( self, @@ -51,15 +51,17 @@ def test_save_led_config_cli( """ self.assertTrue(nuc_wmi.cli.led_app_notification.save_led_config is nuc_wmi_cli_save_led_config) - self.assertTrue(nuc_wmi.cli.led_app_notification.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.led_app_notification.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.led_app_notification.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.led_app_notification.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that save_led_config_cli returns the proper JSON response and exit # code for valid cli args returned_save_led_config_cli = save_led_config_cli([]) nuc_wmi_cli_save_led_config.assert_called_with( - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -73,10 +75,23 @@ def test_save_led_config_cli( self.assertEqual(returned_save_led_config_cli, None) - # Reset - nuc_wmi_cli_save_led_config.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.led_app_notification.print') + @patch('nuc_wmi.cli.led_app_notification.sys.exit') + @patch('nuc_wmi.cli.led_app_notification.save_led_config') + def test_save_led_config_cli2( + self, + nuc_wmi_cli_save_led_config, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `save_led_config_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.led_app_notification.save_led_config is nuc_wmi_cli_save_led_config) + self.assertTrue(nuc_wmi.cli.led_app_notification.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.led_app_notification.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that save_led_config_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -85,7 +100,9 @@ def test_save_led_config_cli( returned_save_led_config_cli = save_led_config_cli([]) nuc_wmi_cli_save_led_config.assert_called_with( - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/query_led_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/query_led_test.py index 129bc7d..26031d9 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/query_led_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/query_led_test.py @@ -50,10 +50,10 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.query_led.print') - @patch('nuc_wmi.cli.query_led.exit') + @patch('nuc_wmi.cli.query_led.sys.exit') @patch('nuc_wmi.cli.query_led.query_led_color_type') def test_query_led_color_type_cli( self, @@ -66,8 +66,8 @@ def test_query_led_color_type_cli( """ self.assertTrue(nuc_wmi.cli.query_led.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.query_led.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that query_led_color_type_cli returns the proper JSON response and exit # code for valid cli args @@ -82,7 +82,9 @@ def test_query_led_color_type_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -97,10 +99,23 @@ def test_query_led_color_type_cli( self.assertEqual(returned_query_led_color_type_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.query_led.print') + @patch('nuc_wmi.cli.query_led.sys.exit') + @patch('nuc_wmi.cli.query_led.query_led_color_type') + def test_query_led_color_type_cli2( + self, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `query_led_color_type_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.query_led.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that query_led_color_type_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -114,7 +129,9 @@ def test_query_led_color_type_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) @@ -123,11 +140,59 @@ def test_query_led_color_type_cli( @patch('nuc_wmi.cli.query_led.print') - @patch('nuc_wmi.cli.query_led.exit') + @patch('nuc_wmi.cli.query_led.sys.exit') + @patch('nuc_wmi.cli.query_led.query_led_color_type') + def test_query_led_color_type_cli3( + self, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `query_led_color_type_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.query_led.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 3: Test that query_led_color_type_cli returns the proper JSON response and exit + # code for valid cli args + + # Return HDD LED color type of Single-color LED + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Single-color LED') + returned_query_led_color_type_cli = query_led_color_type_cli( + [ + LED_TYPE['new'][1] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'color_type': LED_COLOR_TYPE['new'][3] + } + } + ) + + self.assertEqual(returned_query_led_color_type_cli, None) + + + @patch('nuc_wmi.cli.query_led.print') + @patch('nuc_wmi.cli.query_led.sys.exit') @patch('nuc_wmi.cli.query_led.query_led_color_type') @patch('nuc_wmi.cli.query_led.query_led_indicator_options') @patch('nuc_wmi.cli.query_led.query_led_control_items') - def test_query_led_control_items_cli( + def test_query_led_control_items_cli( # pylint: disable=too-many-arguments,too-many-statements self, nuc_wmi_query_led_control_items, nuc_wmi_query_led_indicator_options, @@ -142,16 +207,16 @@ def test_query_led_control_items_cli( self.assertTrue(nuc_wmi.cli.query_led.query_led_control_items is nuc_wmi_query_led_control_items) self.assertTrue(nuc_wmi.cli.query_led.query_led_indicator_options is nuc_wmi_query_led_indicator_options) self.assertTrue(nuc_wmi.cli.query_led.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.query_led.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that query_led_control_items_cli returns the proper JSON response and exit # code for valid cli args # Get control items for HDD LED set to HDD Activity Indicator - expected_control_items = [0x00, 0x01, 0x02, 0x03] + expected_control_items = [0, 1, 2, 3] nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] nuc_wmi_query_led_control_items.return_value = expected_control_items returned_query_led_control_items_cli = query_led_control_items_cli( [ @@ -162,16 +227,22 @@ def test_query_led_control_items_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_control_items.assert_called_with( LED_TYPE['new'].index('HDD LED'), LED_INDICATOR_OPTION.index('HDD Activity Indicator'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -188,18 +259,34 @@ def test_query_led_control_items_cli( self.assertEqual(returned_query_led_control_items_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_query_led_control_items.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.query_led.print') + @patch('nuc_wmi.cli.query_led.sys.exit') + @patch('nuc_wmi.cli.query_led.query_led_color_type') + @patch('nuc_wmi.cli.query_led.query_led_indicator_options') + @patch('nuc_wmi.cli.query_led.query_led_control_items') + def test_query_led_control_items_cli2( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `query_led_control_items_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.query_led.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.query_led.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.query_led.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that query_led_control_items_cli captures raised errors and returns # the proper JSON error response and exit code. - expected_control_items = [0x00, 0x01, 0x02, 0x03] nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] nuc_wmi_query_led_control_items.side_effect = NucWmiError('Error (Function not supported)') returned_query_led_control_items_cli = query_led_control_items_cli( [ @@ -210,31 +297,54 @@ def test_query_led_control_items_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_control_items.assert_called_with( LED_TYPE['new'].index('HDD LED'), LED_INDICATOR_OPTION.index('HDD Activity Indicator'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_query_led_control_items_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_query_led_control_items.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.query_led.print') + @patch('nuc_wmi.cli.query_led.sys.exit') + @patch('nuc_wmi.cli.query_led.query_led_color_type') + @patch('nuc_wmi.cli.query_led.query_led_indicator_options') + @patch('nuc_wmi.cli.query_led.query_led_control_items') + def test_query_led_control_items_cli3( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `query_led_control_items_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.query_led.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.query_led.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.query_led.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 3: Tests that invalid LED indicator raises appropriate error. - expected_control_items = [0x00, 0x01, 0x02, 0x03] + expected_control_items = [0, 1, 2, 3] nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') nuc_wmi_query_led_indicator_options.return_value = [] nuc_wmi_query_led_control_items.return_value = expected_control_items @@ -247,11 +357,15 @@ def test_query_led_control_items_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_print.assert_called_with('{"error": "Invalid indicator option for the selected LED"}') @@ -261,7 +375,7 @@ def test_query_led_control_items_cli( @patch('nuc_wmi.cli.query_led.print') - @patch('nuc_wmi.cli.query_led.exit') + @patch('nuc_wmi.cli.query_led.sys.exit') @patch('nuc_wmi.cli.query_led.query_led_indicator_options') def test_query_led_indicator_options_cli( self, @@ -274,14 +388,14 @@ def test_query_led_indicator_options_cli( """ self.assertTrue(nuc_wmi.cli.query_led.query_led_indicator_options is nuc_wmi_query_led_indicator_options) - self.assertTrue(nuc_wmi.cli.query_led.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that query_led_indicator_options_cli returns the proper JSON response and exit # code for valid cli args # Return HDD LED indicator options of HDD Activity Indicator and Software Indicator - expected_indicator_options = [0x01, 0x04] + expected_indicator_options = [1, 4] nuc_wmi_query_led_indicator_options.return_value = expected_indicator_options returned_query_led_indicator_options_cli = query_led_indicator_options_cli( [ @@ -291,7 +405,9 @@ def test_query_led_indicator_options_cli( nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -306,10 +422,23 @@ def test_query_led_indicator_options_cli( self.assertEqual(returned_query_led_indicator_options_cli, None) - # Reset - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.query_led.print') + @patch('nuc_wmi.cli.query_led.sys.exit') + @patch('nuc_wmi.cli.query_led.query_led_indicator_options') + def test_query_led_indicator_options_cli2( + self, + nuc_wmi_query_led_indicator_options, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `query_led_indicator_options_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.query_led.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that query_led_indicator_options_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -323,7 +452,9 @@ def test_query_led_indicator_options_cli( nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) @@ -332,7 +463,7 @@ def test_query_led_indicator_options_cli( @patch('nuc_wmi.cli.query_led.print') - @patch('nuc_wmi.cli.query_led.exit') + @patch('nuc_wmi.cli.query_led.sys.exit') @patch('nuc_wmi.cli.query_led.query_leds') def test_query_leds_cli( self, @@ -345,17 +476,19 @@ def test_query_leds_cli( """ self.assertTrue(nuc_wmi.cli.query_led.query_leds is nuc_wmi_query_leds) - self.assertTrue(nuc_wmi.cli.query_led.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that query_leds_cli returns the proper JSON response and exit # code for valid cli args - expected_leds = [0x00, 0x01] + expected_leds = [0, 1] nuc_wmi_query_leds.return_value = expected_leds returned_query_leds_cli = query_leds_cli([]) nuc_wmi_query_leds.assert_called_with( - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -367,10 +500,23 @@ def test_query_leds_cli( self.assertEqual(returned_query_leds_cli, None) - # Reset - nuc_wmi_query_leds.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.query_led.print') + @patch('nuc_wmi.cli.query_led.sys.exit') + @patch('nuc_wmi.cli.query_led.query_leds') + def test_query_leds_cli2( + self, + nuc_wmi_query_leds, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `query_leds_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.query_led.query_leds is nuc_wmi_query_leds) + self.assertTrue(nuc_wmi.cli.query_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.query_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that query_leds_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -379,7 +525,9 @@ def test_query_leds_cli( returned_query_leds_cli = query_leds_cli([]) nuc_wmi_query_leds.assert_called_with( - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_control_item_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_control_item_test.py index 40b8f2a..f7386e6 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_control_item_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_control_item_test.py @@ -11,10 +11,11 @@ import json import unittest -from mock import MagicMock, patch +from mock import patch -from nuc_wmi import CONTROL_ITEM, CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, LED_BRIGHTNESS_MULTI_COLOR -from nuc_wmi import LED_COLOR, LED_COLOR_TYPE, LED_INDICATOR_OPTION, LED_TYPE, NucWmiError +from nuc_wmi import CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR +from nuc_wmi import LED_BLINK_FREQUENCY, LED_BRIGHTNESS_MULTI_COLOR, LED_COLOR, LED_COLOR_TYPE, LED_INDICATOR_OPTION +from nuc_wmi import LED_TYPE, NucWmiError from nuc_wmi.cli.set_led_control_item import set_led_control_item_cli import nuc_wmi @@ -37,18 +38,20 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.set_led_control_item.print') - @patch('nuc_wmi.cli.set_led_control_item.exit') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') - def test_set_led_control_item_cli( + def test_set_led_control_item_cli( # pylint: disable=too-many-arguments,too-many-statements self, nuc_wmi_set_led_control_item, nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, nuc_wmi_query_led_color_type, nuc_wmi_sys_exit, nuc_wmi_print @@ -60,17 +63,18 @@ def test_set_led_control_item_cli( self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.set_led_control_item.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that set_led_control_item_cli returns the proper JSON response and exit # code for valid cli args # Set HDD LED control item value of 37 for Brightness of HDD Activity Indicator - led_brightness = 0x37 + led_brightness = 37 nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_set_led_control_item_cli = set_led_control_item_cli( [ LED_TYPE['new'][1], @@ -82,12 +86,17 @@ def test_set_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_called_with( LED_TYPE['new'].index('HDD LED'), @@ -99,7 +108,9 @@ def test_set_led_control_item_cli( } ), led_brightness, - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -116,18 +127,39 @@ def test_set_led_control_item_cli( self.assertEqual(returned_set_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_set_led_control_item.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli2( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that set_led_control_item_cli captures raised errors and returns # the proper JSON error response and exit code. - led_brightness = 0x37 + led_brightness = 37 nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] nuc_wmi_set_led_control_item.side_effect = NucWmiError('Error (Function not supported)') returned_set_led_control_item_cli = set_led_control_item_cli( [ @@ -140,12 +172,17 @@ def test_set_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_called_with( LED_TYPE['new'].index('HDD LED'), @@ -157,26 +194,48 @@ def test_set_led_control_item_cli( } ), led_brightness, - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_set_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() - nuc_wmi_set_led_control_item = MagicMock() + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli3( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 3: Test that set_led_control_item_cli raises proper error when an invalid indicator # option for the current LED is chosen and returns he proper JSON error response and exit code. - led_brightness = 0x37 + led_brightness = 37 nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_set_led_control_item_cli = set_led_control_item_cli( [ LED_TYPE['new'][1], @@ -188,12 +247,17 @@ def test_set_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with('{"error": "Invalid indicator option for the selected LED"}') @@ -201,19 +265,40 @@ def test_set_led_control_item_cli( self.assertEqual(returned_set_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_set_led_control_item.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli4( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 4: Test that set_led_control_item_cli raises proper error when there are no control items for # for the current LED and indicator option chosen and returns he proper JSON error response and exit # code. - led_brightness = 0x37 + led_brightness = 37 nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Single-color LED') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04, 0x05] + nuc_wmi_query_led_indicator_options.return_value = [1, 4, 5] returned_set_led_control_item_cli = set_led_control_item_cli( [ LED_TYPE['new'][0], @@ -225,12 +310,17 @@ def test_set_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('Power Button LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('Power Button LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with( @@ -240,19 +330,40 @@ def test_set_led_control_item_cli( self.assertEqual(returned_set_led_control_item_cli, None) - # Reset - nuc_wmi_query_led_color_type.reset_mock() - nuc_wmi_query_led_indicator_options.reset_mock() - nuc_wmi_set_led_control_item.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli5( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 5: Test that set_led_control_item_cli raises proper error when an invalid control item for # for the current LED and indicator option is chosen and returns the proper JSON error response and # exit code. - led_brightness = 0x37 + led_brightness = 37 nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_set_led_control_item_cli = set_led_control_item_cli( [ LED_TYPE['new'][1], @@ -264,12 +375,17 @@ def test_set_led_control_item_cli( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with( @@ -281,14 +397,16 @@ def test_set_led_control_item_cli( @patch('nuc_wmi.cli.set_led_control_item.print') - @patch('nuc_wmi.cli.set_led_control_item.exit') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') - def test_set_led_control_item_cli2( + def test_set_led_control_item_cli6( # pylint: disable=too-many-arguments,too-many-statements self, nuc_wmi_set_led_control_item, nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, nuc_wmi_query_led_color_type, nuc_wmi_sys_exit, nuc_wmi_print @@ -298,16 +416,18 @@ def test_set_led_control_item_cli2( """ self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) - self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.set_led_control_item.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 6: Test setting control item that uses color # Set HDD LED control item to White for Color of HDD Activity Indicator nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_set_led_control_item_cli = set_led_control_item_cli( [ LED_TYPE['new'][1], @@ -319,12 +439,17 @@ def test_set_led_control_item_cli2( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_called_with( LED_TYPE['new'].index('HDD LED'), @@ -336,7 +461,9 @@ def test_set_led_control_item_cli2( } ), LED_COLOR['new']['Dual-color Blue / White'].index('White'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -355,14 +482,16 @@ def test_set_led_control_item_cli2( @patch('nuc_wmi.cli.set_led_control_item.print') - @patch('nuc_wmi.cli.set_led_control_item.exit') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') - def test_set_led_control_item_cli3( + def test_set_led_control_item_cli7( # pylint: disable=too-many-arguments,too-many-statements self, nuc_wmi_set_led_control_item, nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, nuc_wmi_query_led_color_type, nuc_wmi_sys_exit, nuc_wmi_print @@ -372,16 +501,18 @@ def test_set_led_control_item_cli3( """ self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) - self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) - self.assertTrue(nuc_wmi.cli.set_led_control_item.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member # Branch 7: Test setting control item that uses wrong color raises proper error # Set HDD LED control item to wrong color Amber for Color of HDD Activity Indicator nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') - nuc_wmi_query_led_indicator_options.return_value = [0x01, 0x04] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] returned_set_led_control_item_cli = set_led_control_item_cli( [ LED_TYPE['new'][1], @@ -393,12 +524,17 @@ def test_set_led_control_item_cli3( nuc_wmi_query_led_color_type.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_query_led_indicator_options.assert_called_with( LED_TYPE['new'].index('HDD LED'), - control_file=None + control_file=None, + debug=False, + quirks=None ) + nuc_wmi_query_led_control_items.assert_not_called() nuc_wmi_set_led_control_item.assert_not_called() nuc_wmi_print.assert_called_with( @@ -407,3 +543,457 @@ def test_set_led_control_item_cli3( nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_set_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli8( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 8: Test setting control item that uses color + + # Set HDD LED control item to Indigo for Color of HDD Activity Indicator with 1d RGB-color LED type + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 4] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + returned_set_led_control_item_cli = set_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[1], + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'], + LED_COLOR['new']['RGB-color']['1d']['HDD LED'][6] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_set_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + LED_COLOR['new']['RGB-color']['1d']['HDD LED'].index('Indigo'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[1], + 'control_item': CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['1d']['HDD LED'][6] + } + } + ) + + self.assertEqual(returned_set_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli9( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 9: Test setting control item that uses color + + # Set HDD LED control item to 100 for Color of HDD Activity Indicator with 3d RGB-color LED type + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3, 4] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + returned_set_led_control_item_cli = set_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[1], + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'], + LED_COLOR['new']['RGB-color']['3d'][100] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_set_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + LED_COLOR['new']['RGB-color']['3d'].index('100'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[1], + 'control_item': CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR[1]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['3d'][100] + } + } + ) + + self.assertEqual(returned_set_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli10( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 10: Test setting control item that uses color + + # Set HDD LED control item to Indigo for Color of Software Indicator with 1d RGB-color LED type + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + returned_set_led_control_item_cli = set_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4], + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'], + LED_COLOR['new']['RGB-color']['1d']['HDD LED'][6] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_set_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + LED_COLOR['new']['RGB-color']['1d']['HDD LED'].index('Indigo'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4], + 'control_item': CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['1d']['HDD LED'][6] + } + } + ) + + self.assertEqual(returned_set_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli11( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 11: Test setting control item that uses color + + # Set HDD LED control item to 100 for Color of Software Indicator with 3d RGB-color LED type + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3, 4, 5] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + returned_set_led_control_item_cli = set_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4], + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'], + LED_COLOR['new']['RGB-color']['3d'][100] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_set_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Color', + 'Options': LED_COLOR['new'] + } + ), + LED_COLOR['new']['RGB-color']['3d'].index('100'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4], + 'control_item': CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[3]['Control Item'], + 'control_item_value': LED_COLOR['new']['RGB-color']['3d'][100] + } + } + ) + + self.assertEqual(returned_set_led_control_item_cli, None) + + + @patch('nuc_wmi.cli.set_led_control_item.print') + @patch('nuc_wmi.cli.set_led_control_item.sys.exit') + @patch('nuc_wmi.cli.set_led_control_item.query_led_color_type') + @patch('nuc_wmi.cli.set_led_control_item.query_led_control_items') + @patch('nuc_wmi.cli.set_led_control_item.query_led_indicator_options') + @patch('nuc_wmi.cli.set_led_control_item.set_led_control_item') + def test_set_led_control_item_cli12( # pylint: disable=too-many-arguments,too-many-statements + self, + nuc_wmi_set_led_control_item, + nuc_wmi_query_led_indicator_options, + nuc_wmi_query_led_control_items, + nuc_wmi_query_led_color_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_control_item_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_control_item.set_led_control_item is nuc_wmi_set_led_control_item) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_indicator_options is \ + nuc_wmi_query_led_indicator_options) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_control_items is nuc_wmi_query_led_control_items) + self.assertTrue(nuc_wmi.cli.set_led_control_item.query_led_color_type is nuc_wmi_query_led_color_type) + self.assertTrue(nuc_wmi.cli.set_led_control_item.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_control_item.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 12: Test setting control item that uses blinking frequency + + # Set HDD LED control item to 1.0Hz for Blinking Frequency of Software Indicator with 3d RGB-color LED type + nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('RGB-color') + nuc_wmi_query_led_control_items.return_value = [0, 1, 2, 3, 4, 5] + nuc_wmi_query_led_indicator_options.return_value = [1, 4] + returned_set_led_control_item_cli = set_led_control_item_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4], + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[2]['Control Item'], + LED_BLINK_FREQUENCY['new'][10] + ] + ) + + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_indicator_options.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_control_items.assert_not_called() + + nuc_wmi_set_led_control_item.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Blinking Frequency', + 'Options': LED_BLINK_FREQUENCY['new'] + } + ), + LED_BLINK_FREQUENCY['new'].index('1.0Hz'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4], + 'control_item': CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR[2]['Control Item'], + 'control_item_value': LED_BLINK_FREQUENCY['new'][10] + } + } + ) + + self.assertEqual(returned_set_led_control_item_cli, None) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_indictor_option_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_indictor_option_test.py index aa707f7..e42d00a 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_indictor_option_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_indictor_option_test.py @@ -35,11 +35,11 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.set_led_indicator_option.print') - @patch('nuc_wmi.cli.set_led_indicator_option.exit') + @patch('nuc_wmi.cli.set_led_indicator_option.sys.exit') @patch('nuc_wmi.cli.set_led_indicator_option.set_led_indicator_option') def test_set_led_indicator_option_cli( self, @@ -53,8 +53,8 @@ def test_set_led_indicator_option_cli( self.assertTrue(nuc_wmi.cli.set_led_indicator_option.set_led_indicator_option is \ nuc_wmi_set_led_indicator_option) - self.assertTrue(nuc_wmi.cli.set_led_indicator_option.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.set_led_indicator_option.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that set_led_indicator_option_cli returns the proper JSON response and exit # code for valid cli args @@ -70,7 +70,9 @@ def test_set_led_indicator_option_cli( nuc_wmi_set_led_indicator_option.assert_called_with( LED_TYPE['new'].index('HDD LED'), LED_INDICATOR_OPTION.index('HDD Activity Indicator'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -85,10 +87,24 @@ def test_set_led_indicator_option_cli( self.assertEqual(returned_set_led_indicator_option_cli, None) - # Reset - nuc_wmi_set_led_indicator_option.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.set_led_indicator_option.print') + @patch('nuc_wmi.cli.set_led_indicator_option.sys.exit') + @patch('nuc_wmi.cli.set_led_indicator_option.set_led_indicator_option') + def test_set_led_indicator_option_cli2( + self, + nuc_wmi_set_led_indicator_option, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_indicator_option_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.set_led_indicator_option is \ + nuc_wmi_set_led_indicator_option) + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that set_led_indicator_option_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -104,9 +120,61 @@ def test_set_led_indicator_option_cli( nuc_wmi_set_led_indicator_option.assert_called_with( LED_TYPE['new'].index('HDD LED'), LED_INDICATOR_OPTION.index('HDD Activity Indicator'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_set_led_indicator_option_cli, None) + + + @patch('nuc_wmi.cli.set_led_indicator_option.print') + @patch('nuc_wmi.cli.set_led_indicator_option.sys.exit') + @patch('nuc_wmi.cli.set_led_indicator_option.set_led_indicator_option') + def test_set_led_indicator_option_cli3( + self, + nuc_wmi_set_led_indicator_option, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_indicator_option_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.set_led_indicator_option is \ + nuc_wmi_set_led_indicator_option) + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led_indicator_option.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 3: Test that set_led_indicator_option_cli returns the proper JSON response and exit + # code for valid cli args + + # Set HDD LED indicator option to Software Indicator + returned_set_led_indicator_option_cli = set_led_indicator_option_cli( + [ + LED_TYPE['new'][1], + LED_INDICATOR_OPTION[4] + ] + ) + + nuc_wmi_set_led_indicator_option.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_print.assert_called() + self.assertEqual( + json.loads(nuc_wmi_print.call_args.args[0]), + { + 'led': { + 'type': LED_TYPE['new'][1], + 'indicator_option': LED_INDICATOR_OPTION[4] + } + } + ) + + self.assertEqual(returned_set_led_indicator_option_cli, None) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_test.py index 74ac884..87169cf 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/set_led_test.py @@ -36,10 +36,11 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name + @patch('nuc_wmi.cli.set_led.print') - @patch('nuc_wmi.cli.set_led.exit') + @patch('nuc_wmi.cli.set_led.sys.exit') @patch('nuc_wmi.cli.set_led.set_led') def test_set_led_cli( self, @@ -53,8 +54,8 @@ def test_set_led_cli( self.assertTrue(nuc_wmi.cli.set_led.set_led is \ nuc_wmi_set_led) - self.assertTrue(nuc_wmi.cli.set_led.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.set_led.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.set_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that set_led_cli returns the proper JSON response and exit # code for valid cli args @@ -74,7 +75,9 @@ def test_set_led_cli( str(LED_BRIGHTNESS['legacy'].index('47')), LED_BLINK_FREQUENCY['legacy'].index('Always on'), LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Cyan'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -91,10 +94,24 @@ def test_set_led_cli( self.assertEqual(returned_set_led_cli, None) - # Reset - nuc_wmi_set_led.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.set_led.print') + @patch('nuc_wmi.cli.set_led.sys.exit') + @patch('nuc_wmi.cli.set_led.set_led') + def test_set_led_cli2( + self, + nuc_wmi_set_led, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led.set_led is \ + nuc_wmi_set_led) + self.assertTrue(nuc_wmi.cli.set_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that set_led_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -114,17 +131,33 @@ def test_set_led_cli( str(LED_BRIGHTNESS['legacy'].index('47')), LED_BLINK_FREQUENCY['legacy'].index('Always on'), LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Cyan'), - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) self.assertEqual(returned_set_led_cli, None) - # Reset - nuc_wmi_set_led.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.set_led.print') + @patch('nuc_wmi.cli.set_led.sys.exit') + @patch('nuc_wmi.cli.set_led.set_led') + def test_set_led_cli3( + self, + nuc_wmi_set_led, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `set_led_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.set_led.set_led is \ + nuc_wmi_set_led) + self.assertTrue(nuc_wmi.cli.set_led.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.set_led.print is nuc_wmi_print) # pylint: disable=no-member # Branch 3: Tests that invalid LED color raises appropriate error. returned_set_led_cli = set_led_cli( diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/switch_led_type_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/switch_led_type_test.py index 06746c9..4e367d4 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/switch_led_type_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/switch_led_type_test.py @@ -36,10 +36,10 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.switch_led_type.print') - @patch('nuc_wmi.cli.switch_led_type.exit') + @patch('nuc_wmi.cli.switch_led_type.sys.exit') @patch('nuc_wmi.cli.switch_led_type.switch_led_type') def test_switch_led_type_cli( self, @@ -53,15 +53,18 @@ def test_switch_led_type_cli( self.assertTrue(nuc_wmi.cli.switch_led_type.switch_led_type is \ nuc_wmi_switch_led_type) - self.assertTrue(nuc_wmi.cli.switch_led_type.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.switch_led_type.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.switch_led_type.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.switch_led_type.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that switch_led_type_cli returns the proper JSON response and exit # code for valid cli args returned_switch_led_type_cli = switch_led_type_cli([LED_COLOR_GROUP[0]]) nuc_wmi_switch_led_type.assert_called_with( - LED_COLOR_GROUP.index('Single color LED'), control_file=None + LED_COLOR_GROUP.index('Single color LED'), + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -71,10 +74,24 @@ def test_switch_led_type_cli( self.assertEqual(returned_switch_led_type_cli, None) - # Reset - nuc_wmi_switch_led_type.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.switch_led_type.print') + @patch('nuc_wmi.cli.switch_led_type.sys.exit') + @patch('nuc_wmi.cli.switch_led_type.switch_led_type') + def test_switch_led_type_cli2( + self, + nuc_wmi_switch_led_type, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `switch_led_type_cli` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.cli.switch_led_type.switch_led_type is \ + nuc_wmi_switch_led_type) + self.assertTrue(nuc_wmi.cli.switch_led_type.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.switch_led_type.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that switch_led_type_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -83,7 +100,10 @@ def test_switch_led_type_cli( returned_switch_led_type_cli = switch_led_type_cli([LED_COLOR_GROUP[0]]) nuc_wmi_switch_led_type.assert_called_with( - LED_COLOR_GROUP.index('Single color LED'), control_file=None + LED_COLOR_GROUP.index('Single color LED'), + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/version_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/version_test.py index 2f8a105..52b4dcb 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/version_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/cli/version_test.py @@ -35,10 +35,10 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.cli.version.print') - @patch('nuc_wmi.cli.version.exit') + @patch('nuc_wmi.cli.version.sys.exit') @patch('nuc_wmi.cli.version.wmi_interface_spec_compliance_version') def test_wmi_interface_spec_compliance_version_cli( self, @@ -53,8 +53,8 @@ def test_wmi_interface_spec_compliance_version_cli( self.assertTrue(nuc_wmi.cli.version.wmi_interface_spec_compliance_version is \ nuc_wmi_cli_wmi_interface_spec_compliance_version) - self.assertTrue(nuc_wmi.cli.version.exit is nuc_wmi_sys_exit) - self.assertTrue(nuc_wmi.cli.version.print is nuc_wmi_print) + self.assertTrue(nuc_wmi.cli.version.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.version.print is nuc_wmi_print) # pylint: disable=no-member # Branch 1: Test that wmi_interface_spec_compliance_version_cli returns the proper JSON response and exit # code for valid cli args @@ -64,7 +64,9 @@ def test_wmi_interface_spec_compliance_version_cli( returned_wmi_interface_spec_compliance_version_cli = wmi_interface_spec_compliance_version_cli([]) nuc_wmi_cli_wmi_interface_spec_compliance_version.assert_called_with( - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called() self.assertEqual( @@ -74,10 +76,25 @@ def test_wmi_interface_spec_compliance_version_cli( self.assertEqual(returned_wmi_interface_spec_compliance_version_cli, None) - # Reset - nuc_wmi_cli_wmi_interface_spec_compliance_version.reset_mock() - nuc_wmi_sys_exit.reset_mock() - nuc_wmi_print.reset_mock() + + @patch('nuc_wmi.cli.version.print') + @patch('nuc_wmi.cli.version.sys.exit') + @patch('nuc_wmi.cli.version.wmi_interface_spec_compliance_version') + def test_wmi_interface_spec_compliance_version_cli2( + self, + nuc_wmi_cli_wmi_interface_spec_compliance_version, + nuc_wmi_sys_exit, + nuc_wmi_print + ): + """ + Tests that `wmi_interface_spec_compliance_version_cli` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.cli.version.wmi_interface_spec_compliance_version is \ + nuc_wmi_cli_wmi_interface_spec_compliance_version) + self.assertTrue(nuc_wmi.cli.version.sys.exit is nuc_wmi_sys_exit) + self.assertTrue(nuc_wmi.cli.version.print is nuc_wmi_print) # pylint: disable=no-member # Branch 2: Test that wmi_interface_spec_compliance_version_cli captures raised errors and returns # the proper JSON error response and exit code. @@ -86,7 +103,9 @@ def test_wmi_interface_spec_compliance_version_cli( returned_wmi_interface_spec_compliance_version_cli = wmi_interface_spec_compliance_version_cli([]) nuc_wmi_cli_wmi_interface_spec_compliance_version.assert_called_with( - control_file=None + control_file=None, + debug=False, + quirks=None ) nuc_wmi_print.assert_called_with('{"error": "Error (Function not supported)"}') nuc_wmi_sys_exit.assert_called_with(1) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/control_file_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/control_file_test.py index c49c71b..d0ecfeb 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/control_file_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/control_file_test.py @@ -6,15 +6,21 @@ TestControlFile: A unit test class for the functions in `nuc_wmi.control_file`. """ +from __future__ import print_function + import os +import sys import unittest -from mock import patch from tempfile import NamedTemporaryFile +from mock import patch + from nuc_wmi import NucWmiError from nuc_wmi.control_file import read_control_file, write_control_file +import nuc_wmi + class TestControlFile(unittest.TestCase): """ @@ -41,7 +47,7 @@ def setUp(self): """ self.control_file = NamedTemporaryFile(delete=False) - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name self.control_file.close() @@ -56,113 +62,306 @@ def tearDown(self): os.unlink(self.control_file.name) - def test_read_control_file(self): + @patch('nuc_wmi.control_file.print') + def test_read_control_file(self, nuc_wmi_print): """ Tests that `read_control_file` returns the expected exceptions, return values, or outputs. """ + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + # Branch 1: Test that `read_control_file` raises exception when `nuc_wmi.CONTROL_FILE` doesnt exist # Assumes we are testing on a system without the driver installed. - with self.assertRaises((IOError, OSError)) as err: - read_control_file() + with self.assertRaises((IOError, OSError)): + read_control_file( + control_file=None + ) + + nuc_wmi_print.assert_not_called() # Reset with open(self.control_file.name, 'w') as fout: fout.truncate() + + @patch('nuc_wmi.control_file.print') + def test_read_control_file2(self, nuc_wmi_print): + """ + Tests that `read_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + # Branch 2: Test that `read_control_file` raise exception if less than 4 bytes are read with open(self.control_file.name, 'w') as fout: fout.write("00 00 00\n\x00") with self.assertRaises(NucWmiError) as byte_list_len_err: - read_control_file(control_file=self.control_file.name) + read_control_file( + control_file=self.control_file.name, + debug=False, + quirks=None + ) self.assertEqual(str(byte_list_len_err.exception), 'NUC WMI control file did not return an expected 4 bytes') + nuc_wmi_print.assert_not_called() + # Reset with open(self.control_file.name, 'w') as fout: fout.truncate() + + @patch('nuc_wmi.control_file.print') + def test_read_control_file3(self, nuc_wmi_print): + """ + Tests that `read_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + # Branch 3: Test that overriding control file with existing file works with open(self.control_file.name, 'w') as fout: fout.write("0D 0E 0A 0D\n\x00") byte_list = (0x0D, 0x0E, 0x0A, 0x0D) - self.assertEqual(read_control_file(control_file=self.control_file.name), byte_list) + self.assertEqual( + read_control_file( + control_file=self.control_file.name, + debug=False, + quirks=None + ), + byte_list + ) + + nuc_wmi_print.assert_not_called() # Reset with open(self.control_file.name, 'w') as fout: fout.truncate() + + @patch('nuc_wmi.control_file.print') + def test_read_control_file4(self, nuc_wmi_print): + """ + Tests that `read_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + # Branch 4: Test that overriding control file with non existing file raises exception non_existent_file = NamedTemporaryFile() non_existent_file.close() - with self.assertRaises((IOError, OSError)) as err: - read_control_file(control_file=non_existent_file.name) + with self.assertRaises((IOError, OSError)): + read_control_file( + control_file=non_existent_file.name, + debug=False, + quirks=None + ) + + nuc_wmi_print.assert_not_called() + + + @patch('nuc_wmi.control_file.print') + def test_read_control_file5(self, nuc_wmi_print): + """ + Tests that `read_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member # Branch 5: Test that exception is raised if NUC WMI returns a hex byte outside 0-255 range with open(self.control_file.name, 'w') as fout: fout.write("FFF 0E 0A 0D\n\x00") with self.assertRaises(NucWmiError) as err: - read_control_file(control_file=self.control_file.name) + read_control_file( + control_file=self.control_file.name, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'NUC WMI returned hex byte outside of 0-255 range') + nuc_wmi_print.assert_not_called() + - def test_write_control_file(self): + @patch('nuc_wmi.control_file.print') + def test_read_control_file6(self, nuc_wmi_print): + """ + Tests that `read_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 6: Test that debug logging prints read bytes + with open(self.control_file.name, 'w') as fout: + fout.write("0D 0E 0A 0D\n\x00") + + byte_list = (0x0D, 0x0E, 0x0A, 0x0D) + + self.assertEqual( + read_control_file( + control_file=self.control_file.name, + debug=True, + quirks=None + ), + byte_list + ) + + nuc_wmi_print.assert_called_with( + 'r: ', + '0D 0E 0A 0D', + file=sys.stderr + ) + + + @patch('nuc_wmi.control_file.print') + def test_write_control_file(self, nuc_wmi_print): """ Tests that `write_control_file` returns the expected exceptions, return values, or outputs. """ + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + # Branch 1: Tests that `write_control_file` raises the expected exception when `nuc_wmi.CONTROL_FILE` doesnt # exist. Assumes we are testing on a system without the driver installed. - with self.assertRaises((IOError, OSError)) as err: - read_control_file() + with self.assertRaises((IOError, OSError)): + read_control_file( + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_print.assert_not_called() # Reset with open(self.control_file.name, 'w') as fout: fout.truncate() - # Branch 2, 3: Tests that the number of bytes written to the control file are padded to 5 bytes, and that - # integer byte list is properly written to the control file. + + @patch('nuc_wmi.control_file.print') + def test_write_control_file2(self, nuc_wmi_print): + """ + Tests that `write_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 2: Tests that the number of bytes written to the control file are padded to 5 bytes, and that + # integer byte list is properly written to the control file. byte_list = [0x0D, 0x0E, 0x0A, 0x0D] - expected_byte_string='0d 0e 0a 0d 00' + expected_byte_string = '0d 0e 0a 0d 00' - write_control_file(byte_list, control_file=self.control_file.name) + write_control_file( + byte_list, + control_file=self.control_file.name, + debug=False, + quirks=None + ) with open(self.control_file.name, 'r') as fin: written_byte_string = fin.read() self.assertEqual(expected_byte_string, written_byte_string) + nuc_wmi_print.assert_not_called() + # Reset with open(self.control_file.name, 'w') as fout: fout.truncate() - # Branch 4: Tests that an string byte list is properly written to the control file + + @patch('nuc_wmi.control_file.print') + def test_write_control_file3(self, nuc_wmi_print): + """ + Tests that `write_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 3: Tests that an string byte list is properly written to the control file byte_list = [str(0x0D), str(0x0E), str(0x0A), str(0x0D)] - expected_byte_string='0d 0e 0a 0d 00' + expected_byte_string = '0d 0e 0a 0d 00' - write_control_file(byte_list, control_file=self.control_file.name) + write_control_file( + byte_list, + control_file=self.control_file.name, + debug=False, + quirks=None + ) with open(self.control_file.name, 'r') as fin: written_byte_string = fin.read() self.assertEqual(expected_byte_string, written_byte_string) + nuc_wmi_print.assert_not_called() + # Reset with open(self.control_file.name, 'w') as fout: fout.truncate() - # Branch 5: Test that byte strings outside of the 0-255 value raise an exception + + @patch('nuc_wmi.control_file.print') + def test_write_control_file4(self, nuc_wmi_print): + """ + Tests that `write_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 4: Test that byte strings outside of the 0-255 value raise an exception byte_list = [0xFFF] with self.assertRaises(NucWmiError) as err: - write_control_file(byte_list, control_file=self.control_file.name) + write_control_file( + byte_list, + control_file=self.control_file.name, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (NUC LED byte values must be 0-255)') + + nuc_wmi_print.assert_not_called() + + # Reset + with open(self.control_file.name, 'w') as fout: + fout.truncate() + + + @patch('nuc_wmi.control_file.print') + def test_write_control_file5(self, nuc_wmi_print): + """ + Tests that `write_control_file` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.control_file.print is nuc_wmi_print) # pylint: disable=no-member + + # Branch 5: Test that debug logging prints written bytess + + byte_list = [0x0D, 0x0E, 0x0A, 0x0D] + expected_byte_string = '0d 0e 0a 0d 00' + + write_control_file( + byte_list, + control_file=self.control_file.name, + debug=True, + quirks=None + ) + + with open(self.control_file.name, 'r') as fin: + written_byte_string = fin.read() + + self.assertEqual(expected_byte_string, written_byte_string) + + nuc_wmi_print.assert_called_with( + 'w: ', + expected_byte_string, + file=sys.stderr + ) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_new_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_new_test.py index fcc07e6..4ecd5e0 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_new_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_new_test.py @@ -10,8 +10,9 @@ from mock import patch -from nuc_wmi import CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, LED_BRIGHTNESS_MULTI_COLOR, LED_INDICATOR_OPTION -from nuc_wmi import LED_TYPE, NucWmiError +from nuc_wmi import CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR +from nuc_wmi import LED_BLINK_FREQUENCY, LED_BRIGHTNESS_MULTI_COLOR, LED_INDICATOR_OPTION, LED_TYPE +from nuc_wmi import NucWmiError from nuc_wmi.get_led_new import GET_LED_TYPE, METHOD_ID, get_led_control_item, get_led_indicator_option import nuc_wmi @@ -36,7 +37,7 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.get_led_new.read_control_file') @@ -67,7 +68,7 @@ def test_get_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con ] read_byte_list = [ 0x00, - LED_BRIGHTNESS_MULTI_COLOR.index('30'), + 0x30, 0x00, 0x00 ] @@ -81,16 +82,31 @@ def test_get_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con 'Control Item': 'Brightness', 'Options': LED_BRIGHTNESS_MULTI_COLOR } - ) + ), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_get_led_control_item, read_byte_list[1]) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.get_led_new.read_control_file') + @patch('nuc_wmi.get_led_new.write_control_file') + def test_get_led_control_item2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led_control_item` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led_new.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led_new.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that get_led_control_item raises an exception when the control file returns an # error code. @@ -118,7 +134,7 @@ def test_get_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_get_led_control_item = get_led_control_item( + get_led_control_item( len(LED_TYPE['new']), # Incorrect led LED_INDICATOR_OPTION.index('HDD Activity Indicator'), CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR.index( @@ -126,14 +142,137 @@ def test_get_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con 'Control Item': 'Brightness', 'Options': LED_BRIGHTNESS_MULTI_COLOR } - ) + ), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') + @patch('nuc_wmi.get_led_new.read_control_file') + @patch('nuc_wmi.get_led_new.write_control_file') + def test_get_led_control_item3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led_control_item` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led_new.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led_new.write_control_file is nuc_wmi_write_control_file) + + # Branch 3: Test that get_led_control_item sends the expected byte string to the control file + # and that the returned control file response is properly processed. + + # Get RGB Header Software Indicator Brightness of 30% for multi color led + expected_write_byte_list = [ + METHOD_ID, + GET_LED_TYPE.index('get_led_control_item'), + LED_TYPE['new'].index('RGB Header'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Brightness', + 'Options': LED_BRIGHTNESS_MULTI_COLOR + } + ), + ] + read_byte_list = [ + 0x00, + 0x30, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + returned_get_led_control_item = get_led_control_item( + LED_TYPE['new'].index('RGB Header'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Brightness', + 'Options': LED_BRIGHTNESS_MULTI_COLOR + } + ), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + + self.assertEqual(returned_get_led_control_item, read_byte_list[1]) + + @patch('nuc_wmi.get_led_new.read_control_file') + @patch('nuc_wmi.get_led_new.write_control_file') + def test_get_led_control_item4(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led_control_item` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led_new.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led_new.write_control_file is nuc_wmi_write_control_file) + + # Branch 4: Test that get_led_control_item sends the expected byte string to the control file + # and that the returned control file response is properly processed. + + # Get RGB Header Software Indicator Blinking Frequency of 1 Hz for multi color led + expected_write_byte_list = [ + METHOD_ID, + GET_LED_TYPE.index('get_led_control_item'), + LED_TYPE['new'].index('RGB Header'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Blinking Frequency', + 'Options': LED_BLINK_FREQUENCY['new'] + } + ), + ] + read_byte_list = [ + 0x00, + 0x0A, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + returned_get_led_control_item = get_led_control_item( + LED_TYPE['new'].index('RGB Header'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Blinking Frequency', + 'Options': LED_BLINK_FREQUENCY['new'] + } + ), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + + self.assertEqual(returned_get_led_control_item, LED_BLINK_FREQUENCY['new'].index('1.0Hz')) + + @patch('nuc_wmi.get_led_new.read_control_file') @patch('nuc_wmi.get_led_new.write_control_file') def test_get_led_indicator_option(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): @@ -155,23 +294,38 @@ def test_get_led_indicator_option(self, nuc_wmi_write_control_file, nuc_wmi_read ] read_byte_list = [ 0x00, - LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + 0x02, 0x00, 0x00 ] nuc_wmi_read_control_file.return_value = read_byte_list returned_get_led_indicator_option = get_led_indicator_option( - LED_TYPE['new'].index('HDD LED') + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) - self.assertEqual(returned_get_led_indicator_option, read_byte_list[1]) + self.assertEqual(returned_get_led_indicator_option, LED_INDICATOR_OPTION.index('HDD Activity Indicator')) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.get_led_new.read_control_file') + @patch('nuc_wmi.get_led_new.write_control_file') + def test_get_led_indicator_option2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led_indicator_option` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led_new.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led_new.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that get_led_indicator_option raises an exception when the control file returns an # error code. @@ -192,10 +346,107 @@ def test_get_led_indicator_option(self, nuc_wmi_write_control_file, nuc_wmi_read nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_get_led_indicator_option = get_led_indicator_option( - len(LED_TYPE['new']) # Incorrect led + get_led_indicator_option( + len(LED_TYPE['new']), # Incorrect led + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') + + + @patch('nuc_wmi.get_led_new.read_control_file') + @patch('nuc_wmi.get_led_new.write_control_file') + def test_get_led_indicator_option3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led_indicator_option` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led_new.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led_new.write_control_file is nuc_wmi_write_control_file) + + # Branch 3: Test that get_led_indicator_option sends the expected byte string to the control file + # and that the returned control file response is properly processed. + + # Get HDD LED with Software Indicator + expected_write_byte_list = [ + METHOD_ID, + GET_LED_TYPE.index('get_led_indicator_option'), + LED_TYPE['new'].index('HDD LED') + ] + read_byte_list = [ + 0x00, + 0x10, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + returned_get_led_indicator_option = get_led_indicator_option( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + + self.assertEqual(returned_get_led_indicator_option, LED_INDICATOR_OPTION.index('Software Indicator')) + + + @patch('nuc_wmi.get_led_new.read_control_file') + @patch('nuc_wmi.get_led_new.write_control_file') + def test_get_led_indicator_option4(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led_indicator_option` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led_new.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led_new.write_control_file is nuc_wmi_write_control_file) + + # Branch 4: Test that get_led_indicator_option changes the return value format when QUIRKS mode + # NUC10_RETURN_VALUE is enabled. + + # Get HDD LED with HDD Activity Indicator + expected_write_byte_list = [ + METHOD_ID, + GET_LED_TYPE.index('get_led_indicator_option'), + LED_TYPE['new'].index('HDD LED') + ] + read_byte_list = [ + 0x00, + 0x01, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + + returned_get_led_indicator_option = get_led_indicator_option( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=['NUC10_RETURN_VALUE'] + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=['NUC10_RETURN_VALUE'] + ) + + self.assertEqual(returned_get_led_indicator_option, LED_INDICATOR_OPTION.index('HDD Activity Indicator')) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_test.py index c49c7f7..32e69a4 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/get_led_test.py @@ -32,7 +32,7 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.get_led.read_control_file') @@ -61,15 +61,32 @@ def test_get_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): ] nuc_wmi_read_control_file.return_value = read_byte_list - returned_get_led = get_led(LED_TYPE['legacy'].index('S0 Ring LED')) - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + returned_get_led = get_led( + LED_TYPE['legacy'].index('S0 Ring LED'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_get_led, tuple(read_byte_list[1:])) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.get_led.read_control_file') + @patch('nuc_wmi.get_led.write_control_file') + def test_get_led2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that get_led raises an exception when the control file returns an # error code. @@ -77,15 +94,65 @@ def test_get_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): # Incorrect led expected_write_byte_list = [ METHOD_ID, - len(LED_TYPE['legacy']), # Set incorrect led + len(LED_TYPE['legacy']) # Set incorrect led ] read_byte_list = [0xE2, 0x00, 0x00, 0x00] # Return undefined device nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_get_led = get_led(len(LED_TYPE['legacy'])) # Set incorrect led - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + get_led( + len(LED_TYPE['legacy']), + control_file=None, + debug=False, + quirks=None + ) # Set incorrect led + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Undefined device)') + + + @patch('nuc_wmi.get_led.read_control_file') + @patch('nuc_wmi.get_led.write_control_file') + def test_get_led3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `get_led` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.get_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.get_led.write_control_file is nuc_wmi_write_control_file) + + # Branch 3: Test that get_led returns a non null value when we enable the quirks + # mode NUC7_FREQUENCY_DEFAULT. + + # Incorrect led + expected_write_byte_list = [ + METHOD_ID, + LED_TYPE['legacy'].index('S0 Ring LED') + ] + read_byte_list = [0x00, 0x00, 0x00, 0x00] + + nuc_wmi_read_control_file.return_value = read_byte_list + + + returned_get_led = get_led( + LED_TYPE['legacy'].index('S0 Ring LED'), + control_file=None, + debug=False, + quirks=['NUC7_FREQUENCY_DEFAULT'] + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=['NUC7_FREQUENCY_DEFAULT'] + ) + + self.assertEqual(returned_get_led, tuple([0x00, 0x01, 0x00])) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/led_app_notification_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/led_app_notification_test.py index 659379f..b4e0bf6 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/led_app_notification_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/led_app_notification_test.py @@ -32,7 +32,7 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.led_app_notification.read_control_file') @@ -51,15 +51,31 @@ def test_save_led_config(self, nuc_wmi_write_control_file, nuc_wmi_read_control_ read_byte_list = [0x00, 0x00, 0x00, 0x00] nuc_wmi_read_control_file.return_value = read_byte_list - returned_save_led_config = save_led_config() - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + returned_save_led_config = save_led_config( + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_save_led_config, None) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.led_app_notification.read_control_file') + @patch('nuc_wmi.led_app_notification.write_control_file') + def test_save_led_config2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `save_led_config` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.led_app_notification.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.led_app_notification.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that save_led_config raises an exception when the control file returns an # error code. @@ -69,8 +85,17 @@ def test_save_led_config(self, nuc_wmi_write_control_file, nuc_wmi_read_control_ nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_save_led_config = save_led_config() - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + save_led_config( + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Function not supported)') diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/query_led_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/query_led_test.py index 5612627..a2e02c6 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/query_led_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/query_led_test.py @@ -46,7 +46,7 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.query_led.read_control_file') @@ -72,29 +72,44 @@ def test_query_led_color_type(self, nuc_wmi_write_control_file, nuc_wmi_read_con ] read_byte_list = [ 0x00, - LED_COLOR_TYPE['new'].index('Dual-color Blue / White'), + 0x02, 0x00, 0x00 ] nuc_wmi_read_control_file.return_value = read_byte_list returned_query_led_color_type = query_led_color_type( - LED_TYPE['new'].index('HDD LED') + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_query_led_color_type, expected_query_led_color_type) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_led_color_type2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `query_led_color_type` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that query_led_color_type raises an exception when the control file returns an # error code. # Incorrect led - expected_query_led_color_type = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_led_color_type'), @@ -110,15 +125,116 @@ def test_query_led_color_type(self, nuc_wmi_write_control_file, nuc_wmi_read_con nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_query_led_color_type = query_led_color_type( - len(LED_TYPE['new']) # Incorrect led index + query_led_color_type( + len(LED_TYPE['new']), # Incorrect led index + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_led_color_type3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `query_led_color_type` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) + + # Branch 3: Test that query_led_color_type send the expected byte string to the control file + # and that the returned control file response is properly processed. + + # Query HDD LED that returns a color type of Single-color LED + expected_query_led_color_type = LED_COLOR_TYPE['new'].index('Single-color LED') + expected_write_byte_list = [ + METHOD_ID, + QUERY_TYPE.index('query_led_color_type'), + LED_TYPE['new'].index('HDD LED') + ] + read_byte_list = [ + 0x00, + 0x08, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + returned_query_led_color_type = query_led_color_type( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + + self.assertEqual(returned_query_led_color_type, expected_query_led_color_type) + + + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_led_color_type4(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `query_led_color_type` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) + + # Branch 4: Test that query_led_color_type changes the return value format when QUIRKS mode + # NUC10_RETURN_VALUE is enabled. + + # Query HDD LED that returns a color type of Single-color LED + expected_query_led_color_type = LED_COLOR_TYPE['new'].index('Single-color LED') + expected_write_byte_list = [ + METHOD_ID, + QUERY_TYPE.index('query_led_color_type'), + LED_TYPE['new'].index('HDD LED') + ] + read_byte_list = [ + 0x00, + 0x03, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + + returned_query_led_color_type = query_led_color_type( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=['NUC10_RETURN_VALUE'] + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=['NUC10_RETURN_VALUE'] + ) + + self.assertEqual(returned_query_led_color_type, expected_query_led_color_type) + + @patch('nuc_wmi.query_led.query_led_color_type') @patch('nuc_wmi.query_led.read_control_file') @patch('nuc_wmi.query_led.write_control_file') @@ -141,7 +257,7 @@ def test_query_led_control_items( # and that the returned control file response is properly processed. # Query control items of HDD LED with HDD Activity Indicator - expected_query_led_control_items = [0x00, 0x01, 0x02, 0x03] + expected_query_led_control_items = [0, 1, 2, 3] expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_led_control_items'), @@ -159,18 +275,45 @@ def test_query_led_control_items( nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') returned_query_led_control_items = query_led_control_items( LED_TYPE['new'].index('HDD LED'), - LED_INDICATOR_OPTION.index('HDD Activity Indicator') + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) - nuc_wmi_query_led_color_type.assert_called_with(LED_TYPE['new'].index('HDD LED'), control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_query_led_control_items, expected_query_led_control_items) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() - nuc_wmi_query_led_color_type.reset_mock() + + @patch('nuc_wmi.query_led.query_led_color_type') + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_led_control_items2( + self, + nuc_wmi_write_control_file, + nuc_wmi_read_control_file, + nuc_wmi_query_led_color_type + ): + """ + Tests that `query_led_control_items` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) + self.assertTrue(nuc_wmi.query_led.query_led_color_type is nuc_wmi_query_led_color_type) # Query control items of HDD LED with Disabled Indicator expected_query_led_control_items = [] @@ -191,24 +334,50 @@ def test_query_led_control_items( nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') returned_query_led_control_items = query_led_control_items( LED_TYPE['new'].index('HDD LED'), - LED_INDICATOR_OPTION_DISABLED + LED_INDICATOR_OPTION_DISABLED, + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) - nuc_wmi_query_led_color_type.assert_called_with(LED_TYPE['new'].index('HDD LED'), control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_color_type.assert_called_with( + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_query_led_control_items, expected_query_led_control_items) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() - nuc_wmi_query_led_color_type.reset_mock() - # Branch 2: Test that query_led_control_items raises an exception when the control file returns an + @patch('nuc_wmi.query_led.query_led_color_type') + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_led_control_items3( + self, + nuc_wmi_write_control_file, + nuc_wmi_read_control_file, + nuc_wmi_query_led_color_type + ): + """ + Tests that `query_led_control_items` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) + self.assertTrue(nuc_wmi.query_led.query_led_color_type is nuc_wmi_query_led_color_type) + + # Branch 3: Test that query_led_control_items raises an exception when the control file returns an # error code. # Incorrect led - expected_query_led_control_items = [0x00, 0x01, 0x02, 0x03] expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_led_control_items'), @@ -226,13 +395,26 @@ def test_query_led_control_items( nuc_wmi_query_led_color_type.return_value = LED_COLOR_TYPE['new'].index('Dual-color Blue / White') with self.assertRaises(NucWmiError) as err: - returned_query_led_control_items = query_led_control_items( + query_led_control_items( len(LED_TYPE['new']), # Invalid led index - LED_INDICATOR_OPTION.index('HDD Activity Indicator') + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) - nuc_wmi_query_led_color_type.assert_called_with(len(LED_TYPE['new']), control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + nuc_wmi_query_led_color_type.assert_called_with( + len(LED_TYPE['new']), + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') @@ -252,7 +434,7 @@ def test_query_led_indicator_options(self, nuc_wmi_write_control_file, nuc_wmi_r # and that the returned control file response is properly processed. # Query HDD LED indicator options - expected_query_led_indicator_options = [0x01, 0x04] + expected_query_led_indicator_options = [1, 4] expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_led_indicator_options'), @@ -267,22 +449,37 @@ def test_query_led_indicator_options(self, nuc_wmi_write_control_file, nuc_wmi_r nuc_wmi_read_control_file.return_value = read_byte_list returned_query_led_indicator_options = query_led_indicator_options( - LED_TYPE['new'].index('HDD LED') + LED_TYPE['new'].index('HDD LED'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_query_led_indicator_options, expected_query_led_indicator_options) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_led_indicator_options2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `query_led_indicator_options` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that query_led_indicator_options raises an exception when the control file returns an # error code. # Incorrect led - expected_query_led_indicator_options = [0x01, 0x04] expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_led_indicator_options'), @@ -298,11 +495,19 @@ def test_query_led_indicator_options(self, nuc_wmi_write_control_file, nuc_wmi_r nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_query_led_indicator_options = query_led_indicator_options( - len(LED_TYPE['new']) # Incorrect led index + query_led_indicator_options( + len(LED_TYPE['new']), # Incorrect led index + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') @@ -321,7 +526,7 @@ def test_query_leds(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file) # and that the returned control file response is properly processed. # Query HDD LED indicator options - expected_query_leds = [0x00 , 0x01] + expected_query_leds = [0, 1] expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_leds') @@ -334,21 +539,36 @@ def test_query_leds(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file) ] nuc_wmi_read_control_file.return_value = read_byte_list - returned_query_leds = query_leds() + returned_query_leds = query_leds( + control_file=None, + debug=False, + quirks=None + ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_query_leds, expected_query_leds) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.query_led.read_control_file') + @patch('nuc_wmi.query_led.write_control_file') + def test_query_leds2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `query_leds` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.query_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.query_led.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that query_leds raises an exception when the control file returns an # error code. # Incorrect led - expected_query_leds = [0x00, 0x01] expected_write_byte_list = [ METHOD_ID, QUERY_TYPE.index('query_leds') @@ -363,8 +583,17 @@ def test_query_leds(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file) nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_query_leds = query_leds() + query_leds( + control_file=None, + debug=False, + quirks=None + ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Function not supported)') diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_control_item_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_control_item_test.py index 9cb6574..d0cbedf 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_control_item_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_control_item_test.py @@ -10,8 +10,9 @@ from mock import patch -from nuc_wmi import CONTROL_ITEM, CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, LED_BRIGHTNESS_MULTI_COLOR -from nuc_wmi import LED_INDICATOR_OPTION, LED_TYPE, NucWmiError +from nuc_wmi import CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR, CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR +from nuc_wmi import LED_BLINK_FREQUENCY, LED_BRIGHTNESS_MULTI_COLOR, LED_INDICATOR_OPTION, LED_TYPE +from nuc_wmi import NucWmiError from nuc_wmi.set_led_control_item import METHOD_ID, set_led_control_item import nuc_wmi @@ -33,12 +34,12 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.set_led_control_item.read_control_file') @patch('nuc_wmi.set_led_control_item.write_control_file') - def test_Set_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + def test_set_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): """ Tests that `Set_led_control_item` returns the expected exceptions, return values, or outputs. """ @@ -79,16 +80,31 @@ def test_Set_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con 'Options': LED_BRIGHTNESS_MULTI_COLOR } ), - LED_BRIGHTNESS_MULTI_COLOR.index('30') + LED_BRIGHTNESS_MULTI_COLOR.index('30'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_set_led_control_item, None) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.set_led_control_item.read_control_file') + @patch('nuc_wmi.set_led_control_item.write_control_file') + def test_set_led_control_item2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `Set_led_control_item` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led_control_item.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led_control_item.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that set_led_control_item raises an exception when the control file returns an # error code. @@ -116,7 +132,7 @@ def test_Set_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_set_led_control_item = set_led_control_item( + set_led_control_item( len(LED_TYPE['new']), # Incorrect led LED_INDICATOR_OPTION.index('HDD Activity Indicator'), CONTROL_ITEM_HDD_ACTIVITY_INDICATOR_MULTI_COLOR.index( @@ -125,9 +141,76 @@ def test_Set_led_control_item(self, nuc_wmi_write_control_file, nuc_wmi_read_con 'Options': LED_BRIGHTNESS_MULTI_COLOR } ), - LED_BRIGHTNESS_MULTI_COLOR.index('30') + LED_BRIGHTNESS_MULTI_COLOR.index('30'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') + + + @patch('nuc_wmi.set_led_control_item.read_control_file') + @patch('nuc_wmi.set_led_control_item.write_control_file') + def test_set_led_control_item3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `Set_led_control_item` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led_control_item.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led_control_item.write_control_file is nuc_wmi_write_control_file) + + # Branch 3: Test that set_led_control_item sends the expected byte string to the control file + # and that the returned control file response is properly processed. + + # Set HDD LED Softtware Indicator Blinking Frequency of 1Hz for multi color led + expected_write_byte_list = [ + METHOD_ID, + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Blinking Frequency', + 'Options': LED_BLINK_FREQUENCY['new'] + } + ), + LED_BLINK_FREQUENCY['new'].index('1.0Hz') + ] + read_byte_list = [ + 0x00, + 0x00, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + returned_set_led_control_item = set_led_control_item( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + CONTROL_ITEM_SOFTWARE_INDICATOR_MULTI_COLOR.index( + { + 'Control Item': 'Blinking Frequency', + 'Options': LED_BLINK_FREQUENCY['new'] + } + ), + LED_BLINK_FREQUENCY['new'].index('1.0Hz'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + + self.assertEqual(returned_set_led_control_item, None) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_indicator_option_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_indicator_option_test.py index 67eb039..0b3e920 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_indicator_option_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_indicator_option_test.py @@ -32,7 +32,7 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.set_led_indicator_option.read_control_file') @@ -64,16 +64,31 @@ def test_set_led_indicator_option(self, nuc_wmi_write_control_file, nuc_wmi_read nuc_wmi_read_control_file.return_value = read_byte_list returned_set_led_indicator_option = set_led_indicator_option( LED_TYPE['new'].index('HDD LED'), - LED_INDICATOR_OPTION.index('HDD Activity Indicator') + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_set_led_indicator_option, None) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.set_led_indicator_option.read_control_file') + @patch('nuc_wmi.set_led_indicator_option.write_control_file') + def test_set_led_indicator_option2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `set_led_indicator_option` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led_indicator_option.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led_indicator_option.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that set_led_indicator_option raises an exception when the control file returns an # error code. @@ -94,11 +109,64 @@ def test_set_led_indicator_option(self, nuc_wmi_write_control_file, nuc_wmi_read nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_set_led_indicator_option = set_led_indicator_option( + set_led_indicator_option( len(LED_TYPE['new']), # Incorrect led - LED_INDICATOR_OPTION.index('HDD Activity Indicator') + LED_INDICATOR_OPTION.index('HDD Activity Indicator'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') + + + @patch('nuc_wmi.set_led_indicator_option.read_control_file') + @patch('nuc_wmi.set_led_indicator_option.write_control_file') + def test_set_led_indicator_option3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `set_led_indicator_option` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led_indicator_option.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led_indicator_option.write_control_file is nuc_wmi_write_control_file) + + # Branch 3: Test that set_led_indicator_option sends the expected byte string to the control file + # and that the returned control file response is properly processed. + + # Set HDD LED with Software Indicator + expected_write_byte_list = [ + METHOD_ID, + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator') + ] + read_byte_list = [ + 0x00, + 0x00, + 0x00, + 0x00 + ] + + nuc_wmi_read_control_file.return_value = read_byte_list + returned_set_led_indicator_option = set_led_indicator_option( + LED_TYPE['new'].index('HDD LED'), + LED_INDICATOR_OPTION.index('Software Indicator'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) + + self.assertEqual(returned_set_led_indicator_option, None) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_test.py index db748f4..3e12a0b 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/set_led_test.py @@ -32,7 +32,7 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.set_led.read_control_file') @@ -63,16 +63,31 @@ def test_set_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): LED_TYPE['legacy'].index('S0 Ring LED'), LED_BRIGHTNESS['legacy'].index('63'), LED_BLINK_FREQUENCY['legacy'].index('Always on'), - LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow') + LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_set_led, None) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.set_led.read_control_file') + @patch('nuc_wmi.set_led.write_control_file') + def test_set_led2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `set_led` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that set_led raises an exception when the control file returns an # error code. @@ -90,20 +105,35 @@ def test_set_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_set_led = set_led( + set_led( len(LED_TYPE['legacy']), # Set incorrect led LED_BRIGHTNESS['legacy'].index('63'), LED_BLINK_FREQUENCY['legacy'].index('Always on'), - LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow') + LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Function not supported)') - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.set_led.read_control_file') + @patch('nuc_wmi.set_led.write_control_file') + def test_set_led3(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `set_led` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led.write_control_file is nuc_wmi_write_control_file) # Incorrect brightness expected_write_byte_list = [ @@ -118,20 +148,35 @@ def test_set_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_set_led = set_led( + set_led( LED_TYPE['legacy'].index('S0 Ring LED'), len(LED_BRIGHTNESS['legacy']), # Set incorrect brightness LED_BLINK_FREQUENCY['legacy'].index('Always on'), - LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow') + LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.set_led.read_control_file') + @patch('nuc_wmi.set_led.write_control_file') + def test_set_led4(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `set_led` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led.write_control_file is nuc_wmi_write_control_file) # Incorrect frequency expected_write_byte_list = [ @@ -146,20 +191,35 @@ def test_set_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_set_led = set_led( + set_led( LED_TYPE['legacy'].index('S0 Ring LED'), LED_BRIGHTNESS['legacy'].index('63'), len(LED_BLINK_FREQUENCY['legacy']), # Set incorrect frequency - LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow') + LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']].index('Yellow'), + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.set_led.read_control_file') + @patch('nuc_wmi.set_led.write_control_file') + def test_set_led5(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `set_led` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.set_led.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.set_led.write_control_file is nuc_wmi_write_control_file) # Incorrect color expected_write_byte_list = [ @@ -174,13 +234,21 @@ def test_set_led(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_set_led = set_led( + set_led( LED_TYPE['legacy'].index('S0 Ring LED'), LED_BRIGHTNESS['legacy'].index('63'), LED_BLINK_FREQUENCY['legacy'].index('Always on'), - len(LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']]) # Set incorrect color + len(LED_COLOR['legacy'][LED_COLOR_TYPE['legacy']['S0 Ring LED']]), # Set incorrect color + control_file=None, + debug=False, + quirks=None ) - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/switch_led_type_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/switch_led_type_test.py index a41fe89..211027c 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/switch_led_type_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/switch_led_type_test.py @@ -32,7 +32,7 @@ def setUp(self): Initializes the unit tests; """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.switch_led_type.read_control_file') @@ -51,15 +51,32 @@ def test_switch_led_type(self, nuc_wmi_write_control_file, nuc_wmi_read_control_ read_byte_list = [0x00, 0x00, 0x00, 0x00] nuc_wmi_read_control_file.return_value = read_byte_list - returned_switch_led_type = switch_led_type(LED_COLOR_GROUP.index('Single color LED')) - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + returned_switch_led_type = switch_led_type( + LED_COLOR_GROUP.index('Single color LED'), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_switch_led_type, None) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.switch_led_type.read_control_file') + @patch('nuc_wmi.switch_led_type.write_control_file') + def test_switch_led_type2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `switch_led_type` returns the expected exceptions, return values, or outputs. + """ + + self.assertTrue(nuc_wmi.switch_led_type.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.switch_led_type.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that switch_led_type raises an exception when the control file returns an # error code. @@ -69,8 +86,18 @@ def test_switch_led_type(self, nuc_wmi_write_control_file, nuc_wmi_read_control_ nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_switch_led_type = switch_led_type(len(LED_COLOR_GROUP)) - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + switch_led_type( + len(LED_COLOR_GROUP), + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Invalid Parameter)') diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/utils_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/utils_test.py index 8cda8f0..f8199fc 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/utils_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/utils_test.py @@ -8,7 +8,6 @@ import unittest -from nuc_wmi import NucWmiError from nuc_wmi.utils import byte_list_to_bitmap @@ -30,7 +29,7 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name def test_byte_list_to_bitmap(self): @@ -45,6 +44,12 @@ def test_byte_list_to_bitmap(self): self.assertEqual(str(err.exception), 'int byte values must be 0-255') + + def test_byte_list_to_bitmap2(self): + """ + Tests that `byte_list_to_bitmap` returns the expected exceptions, return values, or outputs. + """ + # Branch 2: Test that `byte_list_to_bitmap` returns the proper bitmap string regardless of whether the inputs # are ints or str. self.assertEqual( @@ -57,12 +62,24 @@ def test_byte_list_to_bitmap(self): '00001101000011100000101000001101' ) + + def test_byte_list_to_bitmap3(self): + """ + Tests that `byte_list_to_bitmap` returns the expected exceptions, return values, or outputs. + """ + # Branch 3: Tests that `byte_list_to_bitmap` explicitly pads each byte to 8 bits. self.assertEqual( byte_list_to_bitmap([0x00]), '00000000' ) + + def test_byte_list_to_bitmap4(self): + """ + Tests that `byte_list_to_bitmap` returns the expected exceptions, return values, or outputs. + """ + # Branch 4: Test that `byte_list_bitmap` raises an exception when the input value is not an int - with self.assertRaises(ValueError) as err: + with self.assertRaises(ValueError): byte_list_to_bitmap(["0xZ"]) diff --git a/contrib/nuc_wmi/python/test/unit/nuc_wmi/version_test.py b/contrib/nuc_wmi/python/test/unit/nuc_wmi/version_test.py index d99fc79..ecb1eb9 100644 --- a/contrib/nuc_wmi/python/test/unit/nuc_wmi/version_test.py +++ b/contrib/nuc_wmi/python/test/unit/nuc_wmi/version_test.py @@ -33,7 +33,7 @@ def setUp(self): Initializes the unit tests. """ - self.maxDiff = None + self.maxDiff = None # pylint: disable=invalid-name @patch('nuc_wmi.version.read_control_file') @@ -54,27 +54,52 @@ def test_wmi_interface_spec_compliance_version(self, nuc_wmi_write_control_file, read_byte_list = [0x00, 0x36, 0x01, 0x00] nuc_wmi_read_control_file.return_value = read_byte_list - returned_wmi_interface_spec_compliance_version = wmi_interface_spec_compliance_version() - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + returned_wmi_interface_spec_compliance_version = wmi_interface_spec_compliance_version( + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(returned_wmi_interface_spec_compliance_version, expected_wmi_interface_spec_compliance_version) - # Reset - nuc_wmi_read_control_file.reset_mock() - nuc_wmi_write_control_file.reset_mock() + + @patch('nuc_wmi.version.read_control_file') + @patch('nuc_wmi.version.write_control_file') + def test_wmi_interface_spec_compliance_version2(self, nuc_wmi_write_control_file, nuc_wmi_read_control_file): + """ + Tests that `wmi_interface_spec_compliance_version` returns the expected exceptions, return values, or + outputs. + """ + + self.assertTrue(nuc_wmi.version.read_control_file is nuc_wmi_read_control_file) + self.assertTrue(nuc_wmi.version.write_control_file is nuc_wmi_write_control_file) # Branch 2: Test that wmi_interface_spec_compliance_version raises an exception when the control file returns an # error code. - expected_wmi_interface_spec_compliance_version = (0x01, 0x36) expected_write_byte_list = [METHOD_ID, VERSION_TYPE.index('wmi_interface_spec_compliance_version')] read_byte_list = [0xE1, 0x00, 0x00, 0x00] # Return function not supported nuc_wmi_read_control_file.return_value = read_byte_list with self.assertRaises(NucWmiError) as err: - returned_wmi_interface_spec_compliance_version = wmi_interface_spec_compliance_version() - - nuc_wmi_write_control_file.assert_called_with(expected_write_byte_list, control_file=None) + wmi_interface_spec_compliance_version( + control_file=None, + debug=False, + quirks=None + ) + + nuc_wmi_write_control_file.assert_called_with( + expected_write_byte_list, + control_file=None, + debug=False, + quirks=None + ) self.assertEqual(str(err.exception), 'Error (Function not supported)') diff --git a/contrib/nuc_wmi/setup.py b/contrib/nuc_wmi/setup.py index 05f7214..58d9a03 100644 --- a/contrib/nuc_wmi/setup.py +++ b/contrib/nuc_wmi/setup.py @@ -121,11 +121,12 @@ def test_suite(): 'mock', 'nose', 'nose-cov', + 'pylint', 'setuptools' ], test_suite='setup.test_suite', url='https://github.com/tvision-insights/intel_nuc_led', - version='1.0.0', + version='2.2.0', zip_safe=True, **PYTHON_3_EXTRAS )