File: test_read_and_length.py

package info (click to toggle)
python-dbfread 2.0.7-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 384 kB
  • sloc: python: 1,146; makefile: 140
file content (42 lines) | stat: -rw-r--r-- 1,216 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
37
38
39
40
41
42
"""
Tests reading from database.
"""
from pytest import fixture
import datetime
from .dbf import DBF

@fixture
def table():
    return DBF('testcases/memotest.dbf')

@fixture
def loaded_table():
    return DBF('testcases/memotest.dbf', load=True)

# This relies on people.dbf having this exact content.
records = [{u'NAME': u'Alice',
            u'BIRTHDATE': datetime.date(1987, 3, 1),
            u'MEMO': u'Alice memo'},
           {u'NAME': u'Bob',
            u'BIRTHDATE': datetime.date(1980, 11, 12),
            u'MEMO': u'Bob memo'}]
deleted_records = [{u'NAME': u'Deleted Guy',
                    u'BIRTHDATE': datetime.date(1979, 12, 22),
                    u'MEMO': u'Deleted Guy memo'}]

def test_len(table, loaded_table):
    assert len(table) == 2
    assert len(table.deleted) == 1

    assert len(loaded_table) == 2
    assert len(loaded_table.deleted) == 1

def test_list(table, loaded_table):
    assert list(table) == records
    assert list(table.deleted) == deleted_records
    
    assert list(loaded_table) == records
    assert list(loaded_table.deleted) == deleted_records

    # This should not return old style table which was a subclass of list.
    assert not isinstance(table, list)