Ejemplo n.º 1
0
 def test_timestr_to_secs_with_numbers(self):
     for inp, exp in [(1, 1), (42, 42), (1.1, 1.1), (3.142, 3.142),
                      (-1, -1), (-1.1, -1.1), (0, 0), (0.55555, 0.556),
                      (11.111111, 11.111), ('1e2', 100), ('-1.5e3', -1500)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
         if not isinstance(inp, str):
             assert_equal(timestr_to_secs(str(inp)), exp, inp)
Ejemplo n.º 2
0
 def test_timestr_to_secs_with_numbers(self):
     for inp, exp in [(1, 1),
                      (42, 42),
                      (1.1, 1.1),
                      (3.142, 3.142),
                      (-1, -1),
                      (-1.1, -1.1),
                      (0, 0),
                      (0.55555, 0.556),
                      (11.111111, 11.111),
                      ('1e2', 100),
                      ('-1.5e3', -1500)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
         if not isinstance(inp, basestring):
             assert_equal(timestr_to_secs(str(inp)), exp, inp)
Ejemplo n.º 3
0
    def connect_infomodel(self, timeout=10, alias='default'):
        """Connect to InfoModel. Keyword will wait some `timeout` time for successful connection or throw error if connection fail.

        :param float timeout: Connection timeout.
        """
        timeout = timestr_to_secs(timeout)
        IsNumber().check(timeout)
        IsString().check(alias)
        self.store.get(alias).connect(timeout)
Ejemplo n.º 4
0
 def test_timestr_to_secs_uses_bankers_rounding(self):
     assert_equal(timestr_to_secs(0.1, 0), 0)
     assert_equal(timestr_to_secs(0.5, 0), 0)
     assert_equal(timestr_to_secs(0.51, 0), 1)
     assert_equal(timestr_to_secs(0.99, 0), 1)
     assert_equal(timestr_to_secs(1.0, 0), 1)
     assert_equal(timestr_to_secs(1.499, 0), 1)
     assert_equal(timestr_to_secs(1.5, 0), 2)
Ejemplo n.º 5
0
    def get_infomodel_object(self, dist_name, timeout=10, alias='default'):
        """Get InfoModel object from some `dist_name`. Keyword will wait some `timeout` for successful result or throw error.

        :param string dist_name: Location of InfoModel object.
        :param float timeout: Time in seconds after which getting InfoModel object will fail.
        :param string alias: Name of execution context.
        """
        timeout = timestr_to_secs(timeout)
        IsString().check(dist_name)
        IsNumber().check(timeout)
        IsString().check(alias)
        return self.store.get(alias).get_infomodel_object(dist_name, timeout=timeout)
 def test_timestr_to_secs_with_timer_string(self):
     for inp, exp in [('00:00:00', 0),
                      ('00:00:01', 1),
                      ('01:02:03', 3600 + 2*60 + 3),
                      ('100:00:00', 100*3600),
                      ('1:00:00', 3600),
                      ('11:00:00', 11*3600),
                      ('00:00', 0),
                      ('00:01', 1),
                      ('42:01', 42*60 + 1),
                      ('100:00', 100*60),
                      ('100:100', 100*60 + 100),
                      ('100:100:100', 100*3600 + 100*60 + 100),
                      ('1:1:1', 3600 + 60 + 1),
                      ('0001:0001:0001', 3600 + 60 + 1),
                      ('-00:00:00', 0),
                      ('-00:01:10', -70),
                      ('-1:2:3', -3600 - 2*60 - 3),
                      ('+00:00:00', 0),
                      ('+00:01:10', 70),
                      ('+1:2:3', 3600 + 2*60 + 3),
                      ('00:00:00.0', 0),
                      ('00:00:00.000', 0),
                      ('00:00:00.000000000', 0),
                      ('00:00:00.1', 0.1),
                      ('00:00:00.42', 0.42),
                      ('00:00:00.001', 0.001),
                      ('00:00:00.123', 0.123),
                      ('00:00:00.1234', 0.123),
                      ('00:00:00.12345', 0.123),
                      ('00:00:00.12356', 0.124),
                      ('00:00:00.999', 0.999),
                      ('00:00:00.9995001', 1),
                      ('00:00:00.000000001', 0)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
         if '.' not in inp:
             inp += '.500'
             exp += 0.5 if inp[0] != '-' else -0.5
             assert_equal(timestr_to_secs(inp), exp, inp)
Ejemplo n.º 7
0
 def test_timestr_to_secs_with_timer_string(self):
     for inp, exp in [('00:00:00', 0),
                      ('00:00:01', 1),
                      ('01:02:03', 3600 + 2*60 + 3),
                      ('100:00:00', 100*3600),
                      ('1:00:00', 3600),
                      ('11:00:00', 11*3600),
                      ('00:00', 0),
                      ('00:01', 1),
                      ('42:01', 42*60 + 1),
                      ('100:00', 100*60),
                      ('100:100', 100*60 + 100),
                      ('100:100:100', 100*3600 + 100*60 + 100),
                      ('1:1:1', 3600 + 60 + 1),
                      ('0001:0001:0001', 3600 + 60 + 1),
                      ('-00:00:00', 0),
                      ('-00:01:10', -70),
                      ('-1:2:3', -3600 - 2*60 - 3),
                      ('+00:00:00', 0),
                      ('+00:01:10', 70),
                      ('+1:2:3', 3600 + 2*60 + 3),
                      ('00:00:00.0', 0),
                      ('00:00:00.000', 0),
                      ('00:00:00.000000000', 0),
                      ('00:00:00.1', 0.1),
                      ('00:00:00.42', 0.42),
                      ('00:00:00.001', 0.001),
                      ('00:00:00.123', 0.123),
                      ('00:00:00.1234', 0.123),
                      ('00:00:00.12345', 0.123),
                      ('00:00:00.12356', 0.124),
                      ('00:00:00.999', 0.999),
                      ('00:00:00.9995001', 1),
                      ('00:00:00.000000001', 0)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
         if '.' not in inp:
             inp += '.500'
             exp += 0.5 if inp[0] != '-' else -0.5
             assert_equal(timestr_to_secs(inp), exp, inp)
Ejemplo n.º 8
0
    def set_poll_interval(self, poll_interval):
        """Sets the poll interval used in `Wait Until X` keywords to the given
        value.

        `poll_interval` is given in Robot Framework's time format.

        The old poll interval is returend.

        For more details see `Set Timeout`.
        """

        old = getattr(self, '_poll_interval', 1.0)
        self._poll_interval = robottime.timestr_to_secs(poll_interval)
        return robottime.secs_to_timestr(old)
    def set_poll_interval(self, poll_interval):
        """Sets the poll interval used in `Wait Until X` keywords to the given
        value.

        `poll_interval` is given in Robot Framework's time format.

        The old poll interval is returend.

        For more details see `Set Timeout`.
        """

        old = getattr(self, '_poll_interval', 1.0)
        self._poll_interval = robottime.timestr_to_secs(poll_interval)
        return robottime.secs_to_timestr(old)
Ejemplo n.º 10
0
    def query_infomodel_pararellel_sequences(self, api_version='v1', timeout=10, alias='default', **kw):
        """Query infomodel pararellel sequences. Keyword will wait for successful result some `timeout` time or fail.

        :param string api_version: Query api version. Currently available api version is 'v1'.
        :param float timeout: Time in seconds after witch query sequence will throw InfoModelQueryTimeoutException.
        :param string alias: Name of execution context.

        :note: Experimental keyword.
        """
        timeout = timestr_to_secs(timeout)
        And(IsString(), IsOneOf('v1')).check(api_version)
        IsNumber().check(timeout)
        IsString().check(alias)
        return self.store.get(alias).query_infomodel_pararellel_sequences(sequences=kw, api_version=api_version, timeout=timeout)
Ejemplo n.º 11
0
    def execute_infomodel_operation(self, dist_name, operation, timeout=10, alias='default', *args, **kw):
        """Execute operation on InfoModel object. Keyword will wait some `timeout` for successful operation result or throw error if.operation fail.

        :param string dist_name: Location of InfoModel object.
        :param string operation: Name of operation to execute on InfoModel object.
        :param float timeout: Time in seconds after which attempt to execute operation will fail.
        :param string alias: Name of execution context.
        """
        timeout = timestr_to_secs(timeout)
        IsString().check(dist_name)
        IsString().check(operation)
        IsNumber().check(timeout)
        IsString().check(alias)
        return self.store.get(alias).execute_operation(dist_name, operation, timeout, *args, **kw)
Ejemplo n.º 12
0
    def set_timeout(self, timeout):
        """Sets the timeout used in `Wait Until X` keywords to the given value.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.

        The old timeout is returned and can be used to restore it later.

        Example.
        | ${tout}= | Set Timeout | 2 minute 30 seconds |
        | Do Something |
        | Set Timeout | ${tout} |
        """

        old = getattr(self, '_timeout', 3.0)
        self._timeout = robottime.timestr_to_secs(timeout)
        return robottime.secs_to_timestr(old)
    def set_timeout(self, timeout):
        """Sets the timeout used in `Wait Until X` keywords to the given value.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.

        The old timeout is returned and can be used to restore it later.

        Example.
        | ${tout}= | Set Timeout | 2 minute 30 seconds |
        | Do Something |
        | Set Timeout | ${tout} |
        """

        old = getattr(self, '_timeout', 3.0)
        self._timeout = robottime.timestr_to_secs(timeout)
        return robottime.secs_to_timestr(old)
Ejemplo n.º 14
0
 def test_timestr_to_secs(self):
     for inp, exp in [('1', 1), ('42', 42), (1, 1), (1.1, 1.1),
                      ('3.141', 3.141), ('1s', 1),
                      ('0 day 1 MINUTE 2 S 42 millis', 62.042),
                      ('1minute 0sec 10 millis', 60.01),
                      ('9 9 secs    5  3 4 m i l l i s e co n d s', 99.534),
                      ('10DAY10H10M10SEC', 900610),
                      ('1day 23h 46min 7s 666ms', 171967.666),
                      ('1.5min 1.5s', 91.5), ('1 day', 60 * 60 * 24),
                      ('1 d', 60 * 60 * 24), ('1 hour', 60 * 60),
                      ('1 h', 60 * 60), ('1 minute', 60), ('1 m', 60),
                      ('1 second', 1), ('1 s', 1), ('1 millisecond', 0.001),
                      ('1 ms', 0.001), (-1, -1), (-1.1, -1.1), ('-1', -1),
                      ('-1s', -1), ('-1 min 2 s', -62), ('0.55555', 0.556),
                      (11.111111, 11.111), ('0.1millis', 0),
                      ('0.5ms', 0.001), (0, 0), ('0', 0),
                      ('0day 0hour 0minute 0seconds 0millisecond', 0)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
    def wait_until_rmcp_is_ready(self, timeout=45):
        """Waits until the host can handle RMCP packets.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.
        """

        timeout = robottime.timestr_to_secs(timeout)

        start_time = time.time()
        while time.time() < start_time + timeout:
            try:
                self._ipmi.session.rmcp_ping()
                return
            except TimeoutError:
                pass
            time.sleep(self._poll_interval)

        raise AssertionError('RMCP not ready in %s.' %
                             (robottime.secs_to_timestr(timeout)))
Ejemplo n.º 16
0
    def wait_until_rmcp_is_ready(self, timeout=45):
        """Waits until the host can handle RMCP packets.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.
        """

        timeout = robottime.timestr_to_secs(timeout)

        start_time = time.time()
        while time.time() < start_time + timeout:
            try:
                self._ipmi.session.rmcp_ping()
                return
            except TimeoutError:
                pass
            time.sleep(self._poll_interval)

        raise AssertionError('RMCP not ready in %s.'
                % (robottime.secs_to_timestr(timeout)))
Ejemplo n.º 17
0
 def test_timestr_to_secs_with_time_string(self):
     for inp, exp in [('1s', 1), ('0 day 1 MINUTE 2 S 42 millis', 62.042),
                      ('1minute 0sec 10 millis', 60.01),
                      ('9 9 secs    5  3 4 m i l l i s e co n d s', 99.534),
                      ('10DAY10H10M10SEC', 900610),
                      ('1day 23h 46min 7s 666ms', 171967.666),
                      ('1.5min 1.5s', 91.5), ('1.5 days', 60 * 60 * 36),
                      ('1 day', 60 * 60 * 24), ('2 days', 2 * 60 * 60 * 24),
                      ('1 d', 60 * 60 * 24), ('1 hour', 60 * 60),
                      ('3 hours', 3 * 60 * 60), ('1 h', 60 * 60),
                      ('1 minute', 60), ('2 minutes', 2 * 60),
                      ('1 min', 60), ('2 mins', 2 * 60), ('1 m', 60),
                      ('1 second', 1), ('2 seconds', 2), ('1 sec', 1),
                      ('2 secs', 2), ('1 s', 1), ('1 millisecond', 0.001),
                      ('2 milliseconds', 0.002), ('1 millisec', 0.001),
                      ('2 millisecs', 0.002), ('1234 millis', 1.234),
                      ('1 msec', 0.001), ('2 msecs', 0.002),
                      ('1 ms', 0.001), ('-1s', -1), ('- 1 min 2 s', -62),
                      ('0.1millis', 0), ('0.5ms', 0.001),
                      ('0day 0hour 0minute 0seconds 0millisecond', 0)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
Ejemplo n.º 18
0
 def test_timestr_to_secs_with_time_string(self):
     for inp, exp in [('1s', 1),
                      ('0 day 1 MINUTE 2 S 42 millis', 62.042),
                      ('1minute 0sec 10 millis', 60.01),
                      ('9 9 secs    5  3 4 m i l l i s e co n d s', 99.534),
                      ('10DAY10H10M10SEC', 900610),
                      ('1day 23h 46min 7s 666ms', 171967.666),
                      ('1.5min 1.5s', 91.5),
                      ('1.5 days', 60*60*36),
                      ('1 day', 60*60*24),
                      ('2 days', 2*60*60*24),
                      ('1 d', 60*60*24),
                      ('1 hour', 60*60),
                      ('3 hours', 3*60*60),
                      ('1 h', 60*60),
                      ('1 minute', 60),
                      ('2 minutes', 2*60),
                      ('1 min', 60),
                      ('2 mins', 2*60),
                      ('1 m', 60),
                      ('1 second', 1),
                      ('2 seconds', 2),
                      ('1 sec', 1),
                      ('2 secs', 2),
                      ('1 s', 1),
                      ('1 millisecond', 0.001),
                      ('2 milliseconds', 0.002),
                      ('1 millisec', 0.001),
                      ('2 millisecs', 0.002),
                      ('1234 millis', 1.234),
                      ('1 msec', 0.001),
                      ('2 msecs', 0.002),
                      ('1 ms', 0.001),
                      ('-1s', -1),
                      ('- 1 min 2 s', -62),
                      ('0.1millis', 0),
                      ('0.5ms', 0.001),
                      ('0day 0hour 0minute 0seconds 0millisecond', 0)]:
         assert_equal(timestr_to_secs(inp), exp, inp)
Ejemplo n.º 19
0
 def test_timestr_to_secs(self):
     for inp, exp in [('1', 1),
                      ('42', 42),
                      (1, 1),
                      (1.1, 1.1),
                      ('3.141', 3.141),
                      ('1s', 1),
                      ('0 day 1 MINUTE 2 S 42 millis', 62.042),
                      ('1minute 0sec 10 millis', 60.01),
                      ('9 9 secs    5  3 4 m i l l i s e co n d s', 99.534),
                      ('10DAY10H10M10SEC', 900610),
                      ('1day 23h 46min 7s 666ms', 171967.666),
                      ('1.5min 1.5s', 91.5),
                      ('1 day', 60*60*24),
                      ('1 d', 60*60*24),
                      ('1 hour', 60*60),
                      ('1 h', 60*60),
                      ('1 minute', 60),
                      ('1 m', 60),
                      ('1 second', 1),
                      ('1 s', 1),
                      ('1 millisecond', 0.001),
                      ('1 ms', 0.001),
                      (-1, -1),
                      (-1.1, -1.1),
                      ('-1', -1),
                      ('-1s', -1),
                      ('-1 min 2 s', -62),
                      ('0.55555', 0.556),
                      (11.111111, 11.111),
                      ('0.1millis', 0),
                      ('0.5ms', 0.001),
                      (0, 0),
                      ('0', 0),
                      ('0day 0hour 0minute 0seconds 0millisecond', 0)]:
          assert_equal(timestr_to_secs(inp), exp, inp)
Ejemplo n.º 20
0
 def test_timestr_to_secs_no_rounding(self):
     secs = 0.123456789
     assert_equal(timestr_to_secs(secs, round_to=None), secs)
     assert_equal(timestr_to_secs(str(secs), round_to=None), secs)
Ejemplo n.º 21
0
 def test_timestr_to_secs_rounds_up(self):
     assert_equal(timestr_to_secs(0.5, 0), 1)
     assert_equal(timestr_to_secs(0.9, 0), 1)
     assert_equal(timestr_to_secs(0.1, 0), 0)
Ejemplo n.º 22
0
def format_robot_time(timestr):
    secs = timestr_to_secs(timestr)
    return secs_to_timestr(secs)
Ejemplo n.º 23
0
    def query_infomodel(self, query, api_version='v1', timeout=10, alias='default', extend_result=False):
        """Query InfoModel with some `query`. Keyword will wait for successful result some `timeout` time or fail.

        :param string query: Query expression on InfoModel.

            # example values for `query` parameter:

            # Check that number of `D` objects under /A-1/B-1/C-1 path is more than 1.
            query=count /A-1/B-1/C-1/D-* is > 1

            # Check that number of `D` objects with parameter `ParameterName` equal to `Value` at /A-1/B-1/C-1 path is greater than 1.
            query=count /A-1/B-1/C-1/D-* is [ParameterName=Value] > 1

            # Check that D-1 object exists under /A-1/B-1/C-1 path.
            query=/A-1/B-1/C-1/D-1

            # Check that E-1 object exists under /A-1/B-1/C-1/D-1 path and has two parameters with specified values.
            query=/A-1/B-1/C-1/D-1/E-1 is [ParameterName1=Value1,ParameterName2=Value2]

            # Check that any E-* object exists under /A-1/B-1/C-1/D-1 path and have two parameters with specified values.
            query=/A-1/B-1/C-1/D-1/E-* is [ParameterName1=Value1,ParameterName2=Value2]

            # Check that every E object under /A-1/B-1/C-1/D-1 path have parameters with specified values.
            # At least one object has to match query.
            query=every /A-1/B-1/C-1/D-1/E-* is [ParameterName1=ParamValue1,ParameterName2=ParamValue2]

            # Check that any E object under /A-1/B-1/C-1/D-1 path have parameters with values matched with given regex.
            # At least one object has to match query.
            query=/A-1/B-1/C-1/D-1/E-* is [ParameterName1=regex"ParamValue1",ParameterName2=regex"ParamValue[0-9]"]

            # Check that E-1 object under /A-1/B-1/C-1/D-1 path have parameter, as list, with index 2 equals to "2 index"
            query=/A-1/B-1/C-1/D-1/E-1 is [ParameterName[2]="2 index"]

            # Check that E-1 object under /A-1/B-1/C-1/D-1 path have parameter, as list, where every element are equals to "2 index"
            query=/A-1/B-1/C-1/D-1/E-1 is [ParameterName[*]="2 index"]

            # Check that E-1 object under /A-1/B-1/C-1/D-1 path have parameter, as list, where any element are equals to "2 index"
            query=/A-1/B-1/C-1/D-1/E-1 is [ParameterName[?]="2 index"]

            # Get all E objects under /A-1/B-1/C-1/D-1 path have parameter with specified value"
            query=get list /A-1/B-1/C-1/D-1/E-* is [ParameterName="Value"]

            # Get count of objects which match /A-1/B-1/C-1/D-* is [parameter=value]
            query=get count /A-1/B-1/C-1/D-* is [parameter=value]

            # Check if exists /A-1/B-1 object with empty param Value (e.g. empty list, empty string)
            query=/A-1/B-1 is [Value=empty]

            # Check if exists /A-1/B-1 object with non empty param Value (e.g. list, string)
            query=/A-1/B-1 is [Value!=empty]

        :param string api_version: Query api version. Currently available api version is 'v1'.
        :param boolean extend_result: Extend result with additional data like query data timestamp.
        :param float timeout: Time in seconds after witch query operation will throw InfoModelQueryTimeoutException.
        :param string alias: Name of execution context.

        :rtype: object
        """
        timeout = timestr_to_secs(timeout)
        extend_result = to_bool(extend_result)
        IsString().check(query)
        And(IsString(), IsOneOf('v1')).check(api_version)
        IsNumber().check(timeout)
        IsString().check(alias)
        return self.store.get(alias).query_infomodel(query, api_version, extend_result, timeout)
 def test_timestr_to_secs_rounds_up(self):
     assert_equal(timestr_to_secs(0.5, 0), 1)
     assert_equal(timestr_to_secs(0.9, 0), 1)
     assert_equal(timestr_to_secs(0.1, 0), 0)
Ejemplo n.º 25
0
 def test_timestr_to_secs_custom_rounding(self):
     secs = 0.123456789
     for round_to in 0, 1, 6:
         expected = round(secs, round_to)
         assert_equal(timestr_to_secs(secs, round_to), expected)
         assert_equal(timestr_to_secs(str(secs), round_to), expected)
Ejemplo n.º 26
0
 def test_timestr_to_secs_custom_rounding(self):
     secs = 0.123456789
     for round_to in 0, 1, 6:
         expected = round(secs, round_to)
         assert_equal(timestr_to_secs(secs, round_to), expected)
         assert_equal(timestr_to_secs(str(secs), round_to), expected)
Ejemplo n.º 27
0
 def test_timestr_to_secs_no_rounding(self):
     secs = 0.123456789
     assert_equal(timestr_to_secs(secs, round_to=None), secs)
     assert_equal(timestr_to_secs(str(secs), round_to=None), secs)