Example #1
0
def test_scan_leave_file_in_right_place2():
    f = open(tiny_file)
    result = scan(f, 8)
    assert np.array_equal(result, tiny_arr[:8])
    next = f.readline()
    print next
    print "rest of file:\n", f.read()
    assert next.strip() == "some random text"
Example #2
0
def test_big():
    """
    test scanning a large enough data file to need re-allocating arrays
    """
    N = 10000
    f = open('junk_large.txt', 'w')
    for i in range(N):
        f.write("%f,\n"%3.1459)
    f.close()
    f = open('junk_large.txt', 'r')
    result = scan(f, num_to_read=None)

    assert np.array_equal( result, np.zeros((N,), dtype=np.float64)+3.1459 )
Example #3
0
def test_assert_not_int():
    f = open(tiny_file)
    with pytest.raises(TypeError):
        result = scan(f, 'a_string')
Example #4
0
def test_read_negative_vals():
    # it might as well work
    f = open(tiny_file)
    with pytest.raises(OverflowError):
        result = scan(f, -3)
Example #5
0
def test_read_zero_vals():
    # it might as well work
    f = open(tiny_file)
    result = scan(f, 0)
    assert np.array_equal(result, np.zeros((0,)))
Example #6
0
def test_wrong_file_mode():
    f = open('junk.txt', 'w')
    with pytest.raises(TypeError):
        result = scan(f, 10)
Example #7
0
def test_file_closed():
    f = open(tiny_file)
    f.close()
    with pytest.raises(TypeError):
        result = scan(f, 10)
Example #8
0
def test_assert_not_file():
    with pytest.raises(TypeError):
        f = scan('a_string', 4)
Example #9
0
def test_scan_all():
    f = open(tiny_file)
    result = scan(f)
    print result.shape
    assert np.array_equal(result, tiny_arr)
Example #10
0
def test_scan_leave_file_in_right_place():
    f = open(tiny_file)
    result = scan(f, 10)
    next = f.readline()
    assert next.strip() == ";  3"
Example #11
0
def test_scan_not_enough():
    f = open(tiny_file)
    with pytest.raises(ValueError):
        result = scan(f, 15)
Example #12
0
def test_scan_n():
    f = open(tiny_file)
    result = scan(f, 10)
    assert np.array_equal(tiny_arr[:10], result)
Example #13
0
def test_call():
    " can we even call it"
    f = open(tiny_file)
    result = scan(f, 10)
    print result
    assert True