Пример #1
0
    def test_version_position(self):
        """
    Our 'version' header must be in the second position if validated, but
    otherwise doesn't matter.
    """

        desc = BandwidthFile.from_str(WRONG_VERSION_POSITION)
        self.assertEqual('1.1.0', desc.version)

        self.assertRaisesWith(
            ValueError,
            "The 'version' header must be in the second position",
            BandwidthFile.from_str,
            WRONG_VERSION_POSITION,
            validate=True)

        content = BandwidthFile.content(
            collections.OrderedDict([
                ('timestamp', '1410723598'),
                ('file_created', '2019-01-14T05:35:06'),
                ('version', '1.1.0'),
                ('content', []),
            ]))

        self.assertEqual(RIGHT_VERSION_POSITION, content)
Пример #2
0
  def test_header_alternate_div(self):
    """
    To support backward compatability four character dividers are allowed.
    """

    with open(get_resource('bandwidth_file_v1.2')) as desc_file:
      desc = BandwidthFile.from_str(desc_file.read().replace('=====', '===='))

    self.assertEqual(datetime.datetime(2019, 1, 14, 5, 34, 59), desc.timestamp)
    self.assertEqual('1.2.0', desc.version)
    self.assertEqual(81, len(desc.measurements))
Пример #3
0
 def test_from_str(self):
     sig = BandwidthFile.create()
     self.assertEqual(sig, BandwidthFile.from_str(str(sig)))