def check(self, dtype, word_size=None): if word_size is None: header = FixedLengthHeader.empty() else: header = FixedLengthHeader.empty(word_size) self.assertArrayEqual(header.raw, [-32768] * 256) self.assertEqual(header.raw.dtype, dtype)
def check(self, src_dtype, word_size=None): data = (np.arange(1000) * 10).astype(src_dtype) with self.temp_filename() as filename: data.tofile(filename) with open(filename, "rb") as source: if word_size is None: header = FixedLengthHeader.from_file(source) else: header = FixedLengthHeader.from_file(source, word_size) self.assertArrayEqual(header.raw, np.arange(256) * 10)
def test_equal(self): ffv1 = FixedLengthHeader(list(range(256))) ffv2 = FixedLengthHeader(np.arange(256)) self.assertFalse(ffv1.__ne__(ffv2))
def test_invalid(self): ffv1 = FixedLengthHeader(list(range(256))) self.assertIs(ffv1.__eq__(np.arange(256)), NotImplemented)
def test_equal(self): ffv1 = FixedLengthHeader(range(256)) ffv2 = FixedLengthHeader(range(256)) self.assertTrue(ffv1.__eq__(ffv2))
def test_not_equal(self): ffv1 = FixedLengthHeader(range(256)) ffv2 = FixedLengthHeader(range(256, 512)) self.assertFalse(ffv1.__eq__(ffv2))
def test_invalid(self): ffv1 = FixedLengthHeader(range(256)) self.assertIs(ffv1.__ne__(range(256)), NotImplemented)
def test_not_equal(self): ffv1 = FixedLengthHeader(list(range(256))) ffv2 = FixedLengthHeader(np.arange(256, 512)) self.assertFalse(ffv1.__eq__(ffv2))
def test_invalid_length(self): with self.assertRaisesRegexp(ValueError, 'Incorrect number of words'): FixedLengthHeader(list(range(15)))
def make_header(): return FixedLengthHeader((np.arange(256) + 1) * 10)
def test_invalid(self): ffv1 = FixedLengthHeader(list(range(256))) self.assertIs(ffv1.__ne__(np.arange(256)), NotImplemented)