Skip to content

Commit 0e4f7c4

Browse files
Merge pull request #1207 from glados-verma:examples
PiperOrigin-RevId: 708324379
2 parents 85f5d72 + fd7c8ff commit 0e4f7c4

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

examples/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Running the examples
2+
3+
## Install dependencies
4+
5+
Some examples have their own additional dependencies. They can be installed
6+
with the following command:
7+
8+
```
9+
# Activate your virtualenv if not already done.
10+
pip install pandas
11+
```
12+
13+
## Running the examples
14+
15+
Each example can be run as a Python script, so for `measurements.py`:
16+
17+
```
18+
python examples/measurements.py
19+
```
20+
21+
Running the test will print the outcome on the terminal. You can examine
22+
the run's JSON file, generated in the working directory, to view the
23+
measurements for the run. This example generates a JSON output because it
24+
configures one via output callbacks; read on for more examples with other
25+
types of outputs.
26+
27+
Some examples also have user prompts, you'll have to enter some text at the
28+
prompt to continue the example.
29+
30+
## List of examples
31+
32+
### Canonical examples
33+
34+
1. [`hello_world.py`](hello_world.py): start here if learning how to write
35+
an OpenHTF test.
36+
Comments explain usage of basic OpenHTF features: measurements, phases,
37+
`TestApi` and the OpenHTF test, and output callbacks.
38+
2. [`measurements.py`](measurements.py): measurements are the canonical
39+
mechanism to record text or numeric parameters for a phase.
40+
This example walks you through defining measurements with pass-fail rules ("validators"), units, dimensions, and how to set the measurements from
41+
your phases.
42+
3. [`with_plugs.py`](with_plugs.py): how to define and subclass plugs, and
43+
use them in a phase.
44+
4. [`frontend_example.py`](frontend_example.py): How to use the OpenHTF web
45+
frontend in a test. This gives your test a GUI via the default browser on
46+
the system.
47+
5. [`all_the_things.py`](all_the_things.py): demonstates use of plugs,
48+
measurements, attachments and `PhaseOptions`. Multiple phases are sequenced
49+
via a `Test` and executed, with some output callbacks defined (JSON file,
50+
pickle file and console).
51+
52+
### Feature showcases
53+
54+
1. [`checkpoints.py`](checkpoints.py): checkpoints with measurements can be
55+
used to stop a test if any phase before the checkpoint had failed
56+
measurements.
57+
By default, failed measurements don't stop a test execution.
58+
2. [`stop_on_first_failure.py`](stop_on_first_failure.py): shows how to use
59+
`TestOptions`, in this case the `stop_on_first_failure` option, to
60+
customize test execution.
61+
Also shows how to set this via a `Configuration`.
62+
3. [`ignore_early_canceled_tests.py`](ignore_early_canceled_tests.py): shows
63+
how to customize output callbacks; in this case, JSON output.
64+
4. [`phase_groups.py`](phase_groups.py): phase groups can be used to combine
65+
phases with their own setup and teardown logic.
66+
5. [`repeat.py`](repeat.py): uses `openhtf.PhaseResult.REPEAT` to
67+
conditionally repeat execution of a phase in a test.

examples/measurements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def multdim_measurements(test):
152152
test.measurements['average_voltage'] = power_df['V'].mean()
153153

154154
# We can convert the dataframe to a numpy array as well
155-
power_array = power_df.as_matrix()
155+
power_array = power_df.to_numpy()
156156
test.logger.info('This is the same data in a numpy array:\n%s', power_array)
157157
test.measurements['average_current'] = power_array.mean(axis=0)[2]
158158

examples/with_plugs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class PingDnsB(PingPlug):
7474
@htf.PhaseOptions(name='Ping-{pinger.host}-{count}')
7575
@htf.plug(pinger=PingPlug.placeholder)
7676
@htf.measures('total_time_{pinger.host}_{count}',
77-
htf.Measurement('retcode').equals('{expected_retcode}', type=int))
77+
htf.Measurement('retcode').equals('{expected_retcode}', type=str))
7878
def test_ping(test, pinger, count, expected_retcode):
7979
"""This tests that we can ping a host.
8080

0 commit comments

Comments
 (0)