File: test_207.py

package info (click to toggle)
smart-open 7.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 980 kB
  • sloc: python: 8,054; sh: 90; makefile: 14
file content (36 lines) | stat: -rw-r--r-- 808 bytes parent folder | download
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
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 Radim Rehurek <me@radimrehurek.com>
#
# This code is distributed under the terms and conditions
# from the MIT License (MIT).
#
import os
import sys
import tempfile

try:
    import numpy as np
except ImportError:
    print("You really need numpy to proceed with this test")
    sys.exit(1)

import smart_open


def tofile():
    dt = np.dtype([('time', [('min', int), ('sec', int)]), ('temp', float)])
    x = np.zeros((1,), dtype=dt)

    with tempfile.NamedTemporaryFile(prefix='test_207', suffix='.dat', delete=False) as fout:
        x.tofile(fout.name)
        return fout.name


def test_fromfile():
    try:
        path = tofile()
        with smart_open.smart_open(path, 'rb') as fin:
            np.fromfile(fin)
    finally:
        os.unlink(path)