google / google/openhtf

AssertionError when running with_plugs.py example

Open
#925 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
722
Forks
237
Avg merge
11h 31m
Merged PRs (30d)
4

Description

When running the with_plugs.py example. the following output is generated:

```
$ python3 with_plugs.py
Traceback (most recent call last):
File "with_plugs.py", line 80, in
htf.Measurement('retcode').equals('{expected_retcode}', type=int)
File "/usr/lib/python3.8/site-packages/openhtf/core/measurements.py", line 257, in _with_validator
validators.create_validator(attr, *args, **kwargs))
File "/usr/lib/python3.8/site-packages/openhtf/util/validators.py", line 80, in create_validator
return _VALIDATORS[name](*args, **kwargs)
File "/usr/lib/python3.8/site-packages/openhtf/util/validators.py", line 175, in equals
assert type is None or issubclass(type, six.string_types), (
AssertionError: Cannot use a non-string type when matching a string
```

I believe this is being caused by the `{expected_retcode}` argument to the validator in the measurement not actually being substituted for the argument, so the validator sees its value argument as a string containing `{expected_retcode}` instead of an integer containing the value passed to the test.

```
# Note: phase name and total_time measurement use {} formatting with args
# passed into the phase so each phase has a unique name.
@htf.PhaseOptions(name='Ping-{pinger.host}-{count}')
@htf.plug(pinger=PingPlug.placeholder)
@htf.measures(
'total_time_{pinger.host}_{count}',
htf.Measurement('retcode').equals('{expected_retcode}', type=int)
)
```

I replaced the standard `equals` validator with this one:

```
class MyEquals(ValidatorBase):
def __init__(self, value, type=None):
self.value = value
self.type = type

def __call__(self, value):
print("type(value)) = " + str(type(value)))
print("self.type = " + str(self.type))
print("value = " + str(value))
print("self.value = " + str(self.value))
return type(value) == self.type and value == self.value
```

And this is the output I receive from the validator:

```
type(value)) =
self.type =
value = 0
self.value = {expected_retcode}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.