| # Copyright 2018 The ChromiumOS Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Checks if Whale's cover is opened / closed. |
| |
| Description |
| ----------- |
| |
| Internal references |
| ^^^^^^^^^^^^^^^^^^^ |
| - go/cros_whale_slides |
| |
| Test Procedure |
| -------------- |
| 1. Display instruction to tell the operator to open/close the cover. |
| 2. The operator opens/closes the cover. |
| |
| Dependency |
| ---------- |
| - bft_fixture |
| - Whale |
| |
| Examples |
| -------- |
| An example of checking if whale is closed:: |
| |
| { |
| "pytest_name": "whale_cover", |
| "args": { |
| "bft_fixture": { |
| "class_name": |
| "cros.factory.test.fixture.dummy_bft_fixture.DummyBFTFixture", |
| "params": {} |
| }, |
| "check_interval_secs": 0.2, |
| "check_open": false |
| } |
| } |
| |
| """ |
| |
| import logging |
| |
| from cros.factory.test.fixture import bft_fixture |
| from cros.factory.test.i18n import _ |
| from cros.factory.test import test_case |
| from cros.factory.utils.arg_utils import Arg |
| |
| |
| class WhaleCoverTest(test_case.TestCase): |
| """Checks if Whale's cover is opened / closed.""" |
| related_components = tuple() |
| |
| ARGS = [ |
| Arg('bft_fixture', dict, bft_fixture.TEST_ARG_HELP), |
| Arg('check_interval_secs', (int, float), |
| 'Interval of checking cover', default=0.5), |
| Arg('check_open', bool, |
| "True to check if the cover is open; False to check if it's closed", |
| default=True), |
| ] |
| |
| def CheckCoverStatus(self): |
| """Checks the cover until it's open or closed.""" |
| # yapf: disable |
| if self.args.check_open: # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| hint = _('Please open the cover!') |
| expect_status = self._bft.Status.OPEN |
| else: |
| hint = _('Please close the cover!') |
| expect_status = self._bft.Status.CLOSED |
| |
| done = False |
| try: |
| while not done: |
| done = self._bft.CoverStatus() == expect_status |
| if not done: |
| # yapf: disable |
| self.ui.SetState(hint) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| # yapf: disable |
| self.Sleep(self.args.check_interval_secs) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| except Exception: |
| logging.exception('Failed to check cover status') |
| self.FailTask('Failed to check cover status') |
| |
| self.PassTask() |
| |
| def setUp(self): |
| # yapf: disable |
| self._bft = bft_fixture.CreateBFTFixture(**self.args.bft_fixture) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| |
| def runTest(self): |
| # yapf: disable |
| self.ui.SetState(_('Checking The Cover')) # type: ignore #TODO(b/338318729) Fixit! # pylint: disable=line-too-long |
| # yapf: enable |
| self.CheckCoverStatus() |