File: test_connection.py

package info (click to toggle)
python-loompy 3.0.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,316 kB
  • sloc: python: 3,152; sh: 63; makefile: 16
file content (36 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
from tempfile import NamedTemporaryFile
from unittest import TestCase

import numpy as np
import loompy


class LoomConnectionTests(TestCase):
    def setUp(self) -> None:
        self.file = NamedTemporaryFile(suffix=".loom")
        self.file.close()
        loompy.create(
            self.file.name,
            np.random.random((5, 5)),
            row_attrs={
                "key": np.fromiter(range(5), dtype=np.int)
            },
            col_attrs={
                "key": np.fromiter(range(5), dtype=np.int)
            })

    def tearDown(self) -> None:
        os.remove(self.file.name)

    def test_scan_with_default_ordering(self) -> None:
        with loompy.connect(self.file.name) as ds:
            for axis in [0, 1]:
                _, _, view = next(iter(ds.scan(axis=axis)))
                no_ordering_data = view[:, :]

                _, _, view = next(iter(ds.scan(axis=axis, key="key")))
                original_ordering_data = view[:, :]

        np.testing.assert_almost_equal(no_ordering_data, original_ordering_data,
                                       err_msg="Default ordering should same as in file")