~ubuntu-branches/ubuntu/precise/h5py/precise

« back to all changes in this revision

Viewing changes to h5py/tests/high/test_dataset.py

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2010-03-23 15:38:34 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100323153834-ysfm9nsr8gdnkid3
Tags: 1.3.0-1
* New upstream version.
  - Remove quilt patches.
  - Bump standards version to 3.8.4 (no changes required).
  - Switch to dpkg-source 3.0 (quilt) format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from tempfile import mktemp
 
3
from h5py import tests
 
4
import h5py
 
5
 
 
6
import numpy as np
 
7
 
 
8
class Base(tests.HTest):
 
9
 
 
10
    def setUp(self):
 
11
        self.name = mktemp()
 
12
        self.f = h5py.File(self.name, 'w')
 
13
 
 
14
    def tearDown(self):
 
15
        import os
 
16
        self.f.close()
 
17
        os.unlink(self.name)
 
18
 
 
19
class TestArray(Base):
 
20
 
 
21
    def test_array(self):
 
22
        """ (Dataset) Auto-conversion (2D) """
 
23
        data = np.arange(100).reshape((10,10))
 
24
        ds = self.f.create_dataset('foo', data=data)
 
25
        arr = np.array(ds)
 
26
        self.assertArrayEqual(arr, data)
 
27
 
 
28
    def test_scalar(self):
 
29
        """ (Dataset) Auto-conversion (scalar) """
 
30
        data = np.array(42)
 
31
        ds = self.f.create_dataset('foo', data=data)
 
32
        arr = np.array(ds)
 
33
        self.assertEqual(arr, data)
 
34
 
 
35
    def test_dtype(self):
 
36
        """ (Dataset) Auto-conversion (type) """
 
37
        data = np.arange(100).reshape((10,10)).astype('u8')
 
38
        ds = self.f.create_dataset('foo', data=data)
 
39
        arr = ds.__array__(np.dtype('i1'))
 
40
        self.assertEqual(arr.dtype, np.dtype('i1'))
 
41
        self.assertArrayEqual(arr, data.astype(arr.dtype))
 
42
 
 
43
    def test_fieldname_exc(self):
 
44
        """ (Dataset) Field name on non-compound dataset raises ValueError """
 
45
        ds = self.f.create_dataset('foo', (100,), 'f')
 
46
        self.assertRaises(ValueError, ds.__getitem__, (0, 'a'))
 
47
 
 
48