Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openhtf/util/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ def _asdict(self):
retval[key] = value
return retval

def __dict__(self):
return self._asdict()

@property
def help_text(self):
"""Return a string with all config keys and their descriptions."""
Expand Down
11 changes: 7 additions & 4 deletions openhtf/util/console_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def banner_print(msg, color='', width=60, file=sys.stdout, logger=_LOG):
file.flush()


def bracket_print(msg, color='', width=8, file=sys.stdout):
"""Prints the message in brackets in the specified color and end the line.
def bracket_print(msg, color='', width=8, file=sys.stdout, end_line=True):
"""Prints message in brackets in the specified color, and maybe end the line.

Args:
msg: The message to put inside the brackets (a brief status message).
Expand All @@ -120,6 +120,8 @@ def bracket_print(msg, color='', width=8, file=sys.stdout):
width: Total desired width of the bracketed message.
file: A file object to which the bracketed text will be written. Intended
for use with CLI output file objects like sys.stdout.
end_line: If True, end the line and flush the file object after outputting
the bracketed text.
"""
if CLI_QUIET:
return
Expand All @@ -129,8 +131,9 @@ def bracket_print(msg, color='', width=8, file=sys.stdout):
lpad=lpad, bright=colorama.Style.BRIGHT, color=color, msg=msg,
reset=colorama.Style.RESET_ALL, rpad=rpad))
file.write(colorama.Style.RESET_ALL)
file.write(_linesep_for_file(file))
file.flush()
if end_line:
file.write(_linesep_for_file(file))
file.flush()


def cli_print(msg, color='', end=None, file=sys.stdout, logger=_LOG):
Expand Down
23 changes: 23 additions & 0 deletions openhtf/util/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ def create_validator(name, *args, **kwargs):

class ValidatorBase(with_metaclass(abc.ABCMeta, object)):
@abc.abstractmethod

def __call__(self, value):
"""Should validate value, returning a boolean result."""


class RangeValidatorBase(with_metaclass(abc.ABCMeta, ValidatorBase)):
@abc.abstractproperty

def minimum(self):
"""Should return the minimum, inclusive value of the range."""

Expand All @@ -99,6 +101,27 @@ def maximum(self):


# Built-in validators below this line
class AllInRangeValidator(ValidatorBase):

def __init__(self, min_value, max_value):
self.min_value = min_value
self.max_value = max_value

def __call__(self, values):
return all([self.min_value <= value <= self.max_value for value in values])


class AllEqualsValidator(ValidatorBase):

def __init__(self, spec):
self.spec = spec

def __call__(self, values):
return all([value == self.spec for value in values])

register(AllInRangeValidator, name='all_in_range')
register(AllEqualsValidator, name='all_equals')


class InRange(RangeValidatorBase):
"""Validator to verify a numeric value is within a range."""
Expand Down