Skip to content

Commit c7ab508

Browse files
authored
Internal change (#1004)
[OpenHTF] Ignore the GitHub Actions config file in *.. [OpenHTF] Add util function for getting the phases from a list of phase nodes and phase node collections. Cleanup (3p) LSC: Remove `Lint as` gpylint comment directives. Cleanup (3p) LSC: Remove `Lint as` gpylint comment directives. Support test-stopping failures with a phase-scoped option. Add an explicit Literal annotation to test_state.INFER_MIMETYPE. Add get_test_measurement_strict() into test api. Cleanup Fix or silence upcoming type errors in Python 3.9. Cleanup LSC: Remove `//net/proto2/python/public:use_pure_python` dep, migrate to protobuf Cleanup Silence type errors generated by enabling a new pytype feature. Cleanup Migrate away from Angular's deprecated `async` symbol to use `waitForAsync` Cleanup Fix or ignore type errors generated by the next release of pytype. Iteratively upload attachments in when partial uploads are in use Give mfg_event_converter access to the existing blobref cache Add a size attribute for Attachments Cleanup Remove all usages of //third_party/py/enum library. Cleanup Silence type errors generated by enabling a new pytype feature. Migrate partial upload code from MfgInspector to * Add a mechanism to profile unit tests. Add case formatting options for phase names in OpenHTF Phase Options. Cleanup Remove unused python binaries + libraries from //third_party/py (as reported dead by sensenmann) Cleanup Fix or ignore type errors generated by the next release of pytype. make the mfg_event_converter to handle datetime objects in JSON conversion. (see cl/396863619 for some context) Cleanup Infer `__init__.py` attributes for Python strict deps. validators.py: Use f-string to format Equals str representation. Enable partial upload of attachments from in progress phases Detect changed attachments (and skip cache) to support OpenHTF_record.json Rollback of changelist 392091102. Reason: Rollforward of cl/391826358: Reuse existing blob refs in partial_upload by caching protos Rollback of changelist 391826358. Reason: Seems that these blobrefs are not the correct values to be using at the moment or at least there are occasional issues. See b/197352227 for details. Reuse existing blob refs in partial_upload by caching protos Add alternative for conf.inject_positional_args. Cleanup Fix or ignore type errors generated by the newest pytype release. Move Configuration (openhtf.conf) class attributes to module attributes Treat openhtf.util.conf as an object instead of a module Move Configuration to its own module instead of living in conf Update typescript web_gui files to remove deprecated bypassSecurityTrustHtml Remove __init__.py file that was left behind in an otherwise empty package. Add a protocol and implementation for conf.declare return value. Cleanup Fix or ignore type errors generated by the next release of pytype. PiperOrigin-RevId: 450548096
1 parent 120690a commit c7ab508

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1595
-988
lines changed

contrib/plugs/__init__.py

Whitespace-only changes.

examples/all_the_things.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from six.moves import zip
3333

3434

35-
@htf.plug(example=example_plugs.ExamplePlug)
35+
@htf.plug(example=example_plugs.example_plug_configured)
3636
@htf.plug(frontend_aware=example_plugs.ExampleFrontendAwarePlug)
3737
def example_monitor(example, frontend_aware):
3838
time.sleep(.2)
@@ -50,7 +50,7 @@ def example_monitor(example, frontend_aware):
5050
docstring='Helpful docstring',
5151
units=units.HERTZ,
5252
validators=[util.validators.matches_regex('Measurement')])
53-
@htf.plug(example=example_plugs.ExamplePlug)
53+
@htf.plug(example=example_plugs.example_plug_configured)
5454
@htf.plug(prompts=user_input.UserInput)
5555
def hello_world(test, example, prompts):
5656
"""A hello world test phase."""

examples/example_plugs.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,27 @@
1414
"""Example plugs for OpenHTF."""
1515

1616
from openhtf.core import base_plugs
17-
from openhtf.util import conf
17+
from openhtf.util import configuration
1818

19-
conf.declare(
19+
CONF = configuration.CONF
20+
21+
EXAMPLE_PLUG_INCREMENT_SIZE = CONF.declare(
2022
'example_plug_increment_size',
2123
default_value=1,
2224
description='increment constant for example plug.')
2325

2426

25-
class ExamplePlug(base_plugs.BasePlug): # pylint: disable=no-init
27+
class ExamplePlug(base_plugs.BasePlug):
2628
"""Example of a simple plug.
2729
2830
This plug simply keeps a value and increments it each time increment() is
2931
called. You'll notice a few paradigms here:
3032
31-
- @conf.inject_positional_args
33+
- configuration.bind_init_args
3234
This is generally a good way to pass in any configuration that your
3335
plug needs, such as an IP address or serial port to connect to. If
34-
You want to use your plug outside of the OpenHTF framework, you can
35-
still manually instantiate it, but you must pass the arguments by
36-
keyword (as a side effect of the way inject_positional_args is
37-
implemented).
38-
39-
For example, if you had no openhtf.conf loaded, you could do this:
40-
my_plug = ExamplePlug(example_plug_increment_size=4)
36+
you want to use your plug outside of the OpenHTF framework, you can
37+
still manually instantiate it.
4138
4239
- tearDown()
4340
This method will be called automatically by the OpenHTF framework at
@@ -61,7 +58,6 @@ class ExamplePlug(base_plugs.BasePlug): # pylint: disable=no-init
6158
a with: block at the beginning of every phase where it is used.
6259
"""
6360

64-
@conf.inject_positional_args
6561
def __init__(self, example_plug_increment_size):
6662
self.increment_size = example_plug_increment_size
6763
self.value = 0
@@ -79,6 +75,10 @@ def increment(self):
7975
return self.value - self.increment_size
8076

8177

78+
example_plug_configured = configuration.bind_init_args(
79+
ExamplePlug, EXAMPLE_PLUG_INCREMENT_SIZE)
80+
81+
8282
class ExampleFrontendAwarePlug(base_plugs.FrontendAwareBasePlug):
8383
"""Example of a simple frontend-aware plug.
8484

examples/frontend_example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from openhtf.output.servers import station_server
1818
from openhtf.output.web_gui import web_launcher
1919
from openhtf.plugs import user_input
20-
from openhtf.util import conf
20+
from openhtf.util import configuration
21+
22+
CONF = configuration.CONF
2123

2224

2325
@htf.measures(htf.Measurement('hello_world_measurement'))
@@ -27,7 +29,7 @@ def hello_world(test):
2729

2830

2931
def main():
30-
conf.load(station_server_port='4444')
32+
CONF.load(station_server_port='4444')
3133
with station_server.StationServer() as server:
3234
web_launcher.launch('http://localhost:4444')
3335
for _ in range(5):

examples/stop_on_first_failure.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@
2222
test.configure(stop_on_first_failure=True)
2323
2424
2. Using config item. This option lets you toggle this feature dynamically.
25-
conf.load(stop_on_first_failure=True)
25+
CONF.load(stop_on_first_failure=True)
2626
"""
2727

2828
import openhtf as htf
2929
from openhtf.output.callbacks import console_summary
3030
from openhtf.plugs import user_input
31-
from openhtf.util import conf # pylint: disable=unused-import
31+
from openhtf.util import configuration
3232
from openhtf.util import validators
3333

34+
CONF = configuration.CONF
35+
3436

3537
@htf.measures('number_sum', validators=[validators.in_range(0, 5)])
3638
def add_numbers_fails(test):
@@ -58,7 +60,7 @@ def main():
5860

5961
# Option 2 : You can disable option 1 and enable below line
6062
# to get same result
61-
# conf.load(stop_on_first_failure=True)
63+
# CONF.load(stop_on_first_failure=True)
6264

6365
test.execute(test_start=user_input.prompt_for_test_start())
6466

openhtf/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from openhtf.core.phase_descriptor import diagnose
4141
from openhtf.core.phase_descriptor import measures
4242
from openhtf.core.phase_descriptor import PhaseDescriptor
43+
from openhtf.core.phase_descriptor import PhaseNameCase
4344
from openhtf.core.phase_descriptor import PhaseOptions
4445
from openhtf.core.phase_descriptor import PhaseResult
4546
from openhtf.core.phase_group import PhaseGroup
@@ -50,16 +51,15 @@
5051
from openhtf.core.test_record import PhaseRecord
5152
from openhtf.core.test_record import TestRecord
5253
from openhtf.plugs import plug
53-
from openhtf.util import conf
54+
from openhtf.util import configuration
5455
from openhtf.util import console_output
5556
from openhtf.util import data
5657
from openhtf.util import functions
5758
from openhtf.util import logs
5859
from openhtf.util import units
5960
import pkg_resources
6061

61-
if typing.TYPE_CHECKING:
62-
conf: conf.Configuration # Configuration is only available here in typing.
62+
conf = configuration.CONF
6363

6464

6565
def get_version():

openhtf/core/base_plugs.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,37 @@ def TestPhase(test, example):
6060
Tearing down ExamplePlug!
6161
6262
Plugs will often need to use configuration values. The recommended way
63-
of doing this is with the conf.inject_positional_args decorator:
63+
of doing this is with the configuration.inject_positional_args decorator:
6464
6565
from openhtf import plugs
66-
from openhtf.util import conf
66+
from openhtf.util import configuration
6767
68-
conf.declare('my_config_key', default_value='my_config_value')
68+
CONF = configuration.CONF
69+
MY_CONFIG_KEY = CONF.declare('my_config_key', default_value='my_config_value')
70+
71+
CONF.declare('my_config_key', default_value='my_config_value')
6972
7073
class ExamplePlug(base_plugs.BasePlug):
7174
'''A plug that requires some configuration.'''
7275
73-
@conf.inject_positional_args
7476
def __init__(self, my_config_key)
7577
self._my_config = my_config_key
7678
77-
Note that Plug constructors shouldn't take any other arguments; the
78-
framework won't pass any, so you'll get a TypeError. Any values that are only
79-
known at run time must be either passed into other methods or set via explicit
80-
setter methods. See openhtf/conf.py for details, but with the above
81-
example, you would also need a configuration .yaml file with something like:
79+
example_plug_configured = configuration.bind_init_args(
80+
ExamplePlug, MY_CONFIG_KEY)
81+
82+
Here, example_plug_configured is a subclass of ExamplePlug with bound args for
83+
the initializer, and it can be passed to phases like any other plug. See
84+
openhtf/conf.py for details, but with the above example, you would also need a
85+
configuration .yaml file with something like:
8286
8387
my_config_key: my_config_value
8488
85-
This will result in the ExamplePlug being constructed with
89+
This will result in the example_plug_configured being constructed with
8690
self._my_config having a value of 'my_config_value'.
91+
92+
Note that Plug constructors shouldn't take any other arguments; the
93+
framework won't pass any, so you'll get a TypeError.
8794
"""
8895

8996
import logging
@@ -103,6 +110,18 @@ class InvalidPlugError(Exception):
103110
class BasePlug(object):
104111
"""All plug types must subclass this type.
105112
113+
Okay to use with multiple inheritance when subclassing an existing
114+
implementation that you want to convert into a plug. Place BasePlug last in
115+
the parent list. For example:
116+
117+
class MyExistingDriver:
118+
def do_something(self):
119+
pass
120+
121+
class MyExistingDriverPlug(MyExistingDriver, BasePlug):
122+
def tearDown(self):
123+
... # Implement the BasePlug interface as desired.
124+
106125
Attributes:
107126
logger: This attribute will be set by the PlugManager (and as such it
108127
doesn't appear here), and is the same logger as passed into test phases
@@ -147,14 +166,12 @@ def _asdict(self) -> Dict[Text, Any]:
147166

148167
def tearDown(self) -> None:
149168
"""This method is called automatically at the end of each Test execution."""
150-
pass
151169

152170
@classmethod
153171
def uses_base_tear_down(cls) -> bool:
154172
"""Checks whether the tearDown method is the BasePlug implementation."""
155-
this_tear_down = getattr(cls, 'tearDown')
156-
base_tear_down = getattr(BasePlug, 'tearDown')
157-
return this_tear_down.__code__ is base_tear_down.__code__
173+
this_tear_down = getattr(cls, BasePlug.tearDown.__name__)
174+
return this_tear_down.__code__ is BasePlug.tearDown.__code__
158175

159176

160177
class FrontendAwareBasePlug(BasePlug, util.SubscribableStateMixin):

openhtf/core/diagnoses_lib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Lint as: python3
1615
"""Diagnoses: Measurement and meta interpreters.
1716
1817
Diagnoses are higher level signals that result from processing multiple

openhtf/core/measurements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def validate(self) -> 'Measurement':
439439
raise
440440
finally:
441441
if self._cached:
442-
self._cached['outcome'] = self.outcome.name
442+
self._cached['outcome'] = self.outcome.name # pytype: disable=bad-return-type
443443

444444
def as_base_types(self) -> Dict[Text, Any]:
445445
"""Convert this measurement to a dict of basic types."""

openhtf/core/phase_branches.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# Lint as: python3
1615
"""Implements phase node branches.
1716
1817
A BranchSequence is a phase node sequence that runs conditiionally based on the

0 commit comments

Comments
 (0)