How to use the zhmcclient._utils.datetime_from_timestamp 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
# Expected result, as timezone-unaware (but implied UTC)
        exp_dt_unaware = datetime(*datetime_tuple)

        # Expected result, as timezone-aware
        exp_dt = pytz.utc.localize(exp_dt_unaware)

        if tz_name is None:

            # Execute the code to be tested
            act_dt = datetime_from_timestamp(timestamp)

        else:
            tz = pytz.timezone(tz_name)

            # Execute the code to be tested
            act_dt = datetime_from_timestamp(timestamp, tz)

        # Verify the result.
        # Note: timezone-aware datetime objects compare equal according to
        # their effective point in time (e.g. as if normalized to UTC).
        assert act_dt == exp_dt
github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
"""Test successful calls to datetime_from_timestamp()."""

        if os.name == 'nt' and timestamp > TS_3001_LIMIT:
            # Skip this test case, due to the lower limit on Windows
            return

        # Expected result, as timezone-unaware (but implied UTC)
        exp_dt_unaware = datetime(*datetime_tuple)

        # Expected result, as timezone-aware
        exp_dt = pytz.utc.localize(exp_dt_unaware)

        if tz_name is None:

            # Execute the code to be tested
            act_dt = datetime_from_timestamp(timestamp)

        else:
            tz = pytz.timezone(tz_name)

            # Execute the code to be tested
            act_dt = datetime_from_timestamp(timestamp, tz)

        # Verify the result.
        # Note: timezone-aware datetime objects compare equal according to
        # their effective point in time (e.g. as if normalized to UTC).
        assert act_dt == exp_dt
github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
def x_test_print_max_datetime_from_timestamp(self):
        """Print the maximum for datetime_from_timestamp()."""
        max_ts = find_max_value(datetime_from_timestamp, 1)
        max_dt = datetime_from_timestamp(max_ts)
        print("\nMax HMC timestamp value for zhmcclient."
              "datetime_from_timestamp(): {} ({!r})".format(max_ts, max_dt))
        sys.stdout.flush()
github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
def x_test_print_max_datetime_from_timestamp(self):
        """Print the maximum for datetime_from_timestamp()."""
        max_ts = find_max_value(datetime_from_timestamp, 1)
        max_dt = datetime_from_timestamp(max_ts)
        print("\nMax HMC timestamp value for zhmcclient."
              "datetime_from_timestamp(): {} ({!r})".format(max_ts, max_dt))
        sys.stdout.flush()
github zhmcclient / python-zhmcclient / tests / unit / zhmcclient / test_utils.py View on Github external
def test_error_datetime_from_timestamp(self, timestamp, exc_type):
        """Test failing calls to datetime_from_timestamp()."""

        with pytest.raises(Exception) as exc_info:

            # Execute the code to be tested
            datetime_from_timestamp(timestamp)

        # Verify the result
        assert isinstance(exc_info.value, exc_type)
github zhmcclient / python-zhmcclient / zhmcclient / _metrics.py View on Github external
object_values = list()
                    state = 1
            elif state == 1:
                if mr_line == '':
                    # There are no (or no more) ObjectValues items in this
                    # metrics group
                    state = 0
                else:
                    # There are ObjectValues items
                    resource_uri = mr_line.strip('"')  # No " or \ inside
                    state = 2
            elif state == 2:
                # Process the timestamp
                assert mr_line != ''
                try:
                    dt_timestamp = datetime_from_timestamp(int(mr_line))
                except ValueError:
                    # Sometimes, the returned epoch timestamp values are way
                    # too large, e.g. 3651584404810066 (which would translate
                    # to the year 115791 A.D.). Python datetime supports
                    # up to the year 9999. We circumvent this issue by
                    # simply using the current date&time.
                    # TODO: Remove the circumvention for too large timestamps.
                    dt_timestamp = datetime.now(pytz.utc)
                state = 3
            elif state == 3:
                if mr_line != '':
                    # Process the metric values in the ValueRow line
                    str_values = mr_line.split(',')
                    metrics = dict()
                    for m_name in m_defs:
                        m_def = m_defs[m_name]