How to use the zhmcclient._utils.timestamp_from_datetime function in zhmcclient

To help you get started, we’ve selected a few zhmcclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
"""Test successful calls to timestamp_from_datetime()."""

        # Create a timezone-naive datetime object
        dt = datetime(*datetime_tuple)
        offset = 0  # because of default UTC

        if tz_name is not None:
            # Make the datetime object timezone-aware
            tz = pytz.timezone(tz_name)
            offset = tz.utcoffset(dt).total_seconds()
            dt = tz.localize(dt)

        exp_ts = timestamp - offset * 1000

        # Execute the code to be tested
        ts = timestamp_from_datetime(dt)

        # Verify the result
        assert ts == exp_ts
github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
def test_error(self, datetime_, exc_type):
        """Test failing calls to timestamp_from_datetime()."""

        with pytest.raises(Exception) as exc_info:

            # Execute the code to be tested
            timestamp_from_datetime(datetime_)

        # Verify the result
        assert isinstance(exc_info.value, exc_type)
github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
def test_datetime_max(self):
        """Test timestamp_from_datetime() with datetime.max."""

        # The test is that it does not raise an exception:
        timestamp_from_datetime(datetime.max)
github zhmcclient / python-zhmcclient / zhmcclient / _console.py View on Github external
def _time_query_parms(begin_time, end_time):
        """Return the URI query paramterer string for the specified begin time
        and end time."""
        query_parms = []
        if begin_time is not None:
            begin_ts = timestamp_from_datetime(begin_time)
            qp = 'begin-time={}'.format(begin_ts)
            query_parms.append(qp)
        if end_time is not None:
            end_ts = timestamp_from_datetime(end_time)
            qp = 'end-time={}'.format(end_ts)
            query_parms.append(qp)
        query_parms_str = '&'.join(query_parms)
        if query_parms_str:
            query_parms_str = '?' + query_parms_str
        return query_parms_str
github zhmcclient / python-zhmcclient / zhmcclient_mock / _hmc.py View on Github external
Returns:

          "MetricsResponse" string as described for the "Get Metrics"
            operation response.
        """
        mv_list = self.get_metric_values()
        resp_lines = []
        for mv in mv_list:
            group_name = mv[0]
            resp_lines.append('"{}"'.format(group_name))
            mo_vals = mv[1]
            for mo_val in mo_vals:
                resp_lines.append('"{}"'.format(mo_val.resource_uri))
                resp_lines.append(
                    str(timestamp_from_datetime(mo_val.timestamp)))
                v_list = []
                for n, v in mo_val.values:
                    if isinstance(v, six.string_types):
                        v_str = '"{}"'.format(v)
                    else:
                        v_str = str(v)
                    v_list.append(v_str)
                v_line = ','.join(v_list)
                resp_lines.append(v_line)
                resp_lines.append('')
            resp_lines.append('')
        resp_lines.append('')
        return '\n'.join(resp_lines) + '\n'
github zhmcclient / python-zhmcclient / zhmcclient / _console.py View on Github external
def _time_query_parms(begin_time, end_time):
        """Return the URI query paramterer string for the specified begin time
        and end time."""
        query_parms = []
        if begin_time is not None:
            begin_ts = timestamp_from_datetime(begin_time)
            qp = 'begin-time={}'.format(begin_ts)
            query_parms.append(qp)
        if end_time is not None:
            end_ts = timestamp_from_datetime(end_time)
            qp = 'end-time={}'.format(end_ts)
            query_parms.append(qp)
        query_parms_str = '&'.join(query_parms)
        if query_parms_str:
            query_parms_str = '?' + query_parms_str
        return query_parms_str