Example #1
0
 def test_read_data_call(self):
     # Checks that data is read if read_data is True.
     pp_field = mock.Mock(lblrec=1, lbext=0, lbuser=[0])
     with self.mock_for_field_gen([pp_field]):
         open_fh = mock.Mock()
         open.return_value = open_fh
         next(pp._field_gen('mocked', read_data_bytes=True))
     expected_loaded_bytes = pp.LoadedArrayBytes(open_fh.read(),
                                                 np.dtype('>f4'))
     self.assertEqual(pp_field._data, expected_loaded_bytes)
Example #2
0
 def test_invalid_header_release(self):
     # Check that an unknown LBREL value just results in a warning
     # and the end of the file iteration instead of raising an error.
     with self.temp_filename() as temp_path:
         np.zeros(65, dtype='i4').tofile(temp_path)
         generator = pp._field_gen(temp_path, False)
         with mock.patch('warnings.warn') as warn:
             with self.assertRaises(StopIteration):
                 next(generator)
         self.assertEqual(warn.call_count, 1)
         self.assertIn('header release number', warn.call_args[0][0])
Example #3
0
 def test_read_data_call(self):
     # Checks that data is read if read_data is True.
     pp_field = mock.Mock(lblrec=1, lbext=0, lbuser=[0])
     with self.mock_for_field_gen([pp_field]):
         open_fh = mock.MagicMock(spec=io.RawIOBase)
         open.return_value = open_fh
         next(pp._field_gen("mocked", read_data_bytes=True))
     with open_fh as open_fh_ctx:
         expected_loaded_bytes = pp.LoadedArrayBytes(
             open_fh_ctx.read(), np.dtype(">f4"))
     self.assertEqual(pp_field.data, expected_loaded_bytes)
Example #4
0
 def test_invalid_header_release(self):
     # Check that an unknown LBREL value just results in a warning
     # and the end of the file iteration instead of raising an error.
     with self.temp_filename() as temp_path:
         np.zeros(65, dtype='i4').tofile(temp_path)
         generator = pp._field_gen(temp_path, False)
         with mock.patch('warnings.warn') as warn:
             with self.assertRaises(StopIteration):
                 next(generator)
         self.assertEqual(warn.call_count, 1)
         self.assertIn('header release number', warn.call_args[0][0])
 def test_read_data_call(self):
     # Checks that data is read if read_data is True.
     pp_field = mock.Mock(lblrec=1,
                          lbext=0,
                          lbuser=[0])
     with self.mock_for_field_gen([pp_field]):
         open_fh = mock.Mock()
         open.return_value = open_fh
         next(pp._field_gen('mocked', read_data_bytes=True))
     expected_loaded_bytes = pp.LoadedArrayBytes(open_fh.read(),
                                                 np.dtype('>f4'))
     self.assertEqual(pp_field._data, expected_loaded_bytes)
Example #6
0
 def test_read_headers_call(self):
     # Checks that the two calls to np.fromfile are called in the
     # expected way.
     pp_field = mock.Mock(lblrec=1,
                          lbext=0,
                          lbuser=[0])
     with self.mock_for_field_gen([pp_field]):
         open_fh = mock.Mock()
         open.return_value = open_fh
         next(pp._field_gen('mocked', read_data_bytes=False))
         calls = [mock.call(open_fh, count=45, dtype='>i4'),
                  mock.call(open_fh, count=19, dtype='>f4')]
         np.fromfile.assert_has_calls(calls)
     expected_deferred_bytes = ('mocked', open_fh.tell(),
                                4, np.dtype('>f4'))
     self.assertEqual(pp_field._data, expected_deferred_bytes)
Example #7
0
 def test_read_headers_call(self):
     # Checks that the two calls to np.fromfile are called in the
     # expected way.
     pp_field = mock.Mock(lblrec=1, lbext=0, lbuser=[0])
     with self.mock_for_field_gen([pp_field]):
         open_fh = mock.Mock()
         open.return_value = open_fh
         next(pp._field_gen('mocked', read_data_bytes=False))
         calls = [
             mock.call(open_fh, count=45, dtype='>i4'),
             mock.call(open_fh, count=19, dtype='>f4')
         ]
         np.fromfile.assert_has_calls(calls)
     expected_deferred_bytes = ('mocked', open_fh.tell(), 4,
                                np.dtype('>f4'))
     self.assertEqual(pp_field._data, expected_deferred_bytes)
Example #8
0
 def test_read_headers_call(self):
     # Checks that the two calls to np.fromfile are called in the
     # expected way.
     pp_field = mock.Mock(lblrec=1, lbext=0, lbuser=[0])
     with self.mock_for_field_gen([pp_field]):
         open_fh = mock.MagicMock(spec=io.RawIOBase)
         open.return_value = open_fh
         next(pp._field_gen("mocked", read_data_bytes=False))
         with open_fh as open_fh_ctx:
             calls = [
                 mock.call(open_fh_ctx, count=45, dtype=">i4"),
                 mock.call(open_fh_ctx, count=19, dtype=">f4"),
             ]
         np.fromfile.assert_has_calls(calls)
     with open_fh as open_fh_ctx:
         expected_deferred_bytes = (
             "mocked",
             open_fh_ctx.tell(),
             4,
             np.dtype(">f4"),
         )
     self.assertEqual(pp_field.data, expected_deferred_bytes)
 def gen_fields(self, fields):
     with self.mock_for_field_gen(fields):
         return list(pp._field_gen('mocked', 'mocked'))
Example #10
0
 def gen_fields(self, fields):
     with self.mock_for_field_gen(fields):
         return list(pp._field_gen('mocked', 'mocked'))
Example #11
0
 def gen_fields(self, fields):
     with self.mock_for_field_gen(fields):
         return list(pp._field_gen("mocked", "mocked"))