Skip to content

Commit 6267551

Browse files
committed
test: add table read test
1 parent d88f28a commit 6267551

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ df = pl_access.read_table(file_path, table_name='your_table_name')
5151

5252
This code is based heavily on [jbn's `pandas_access` library](https://github.com/jbn/pandas_access).
5353

54-
## To Do
55-
56-
- [ ] unit tests
57-
- [ ] better error messages when subsections (e.g., schema fetching) fail
58-
5954
## Contributing
6055

6156
Please Star this repo.

tests/test_read_table.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from pathlib import Path
44

5+
import polars as pl
56
import pytest
7+
from polars.testing import assert_frame_equal
68

79
from polars_access_mdbtools import read_table
810

@@ -36,3 +38,28 @@ def test_read_nonexistent_table_raises_value_error(sample_db_1: Path) -> None:
3638
match=f'Table "{nonexistent_table_name}" not found in database',
3739
):
3840
read_table(sample_db_1, nonexistent_table_name)
41+
42+
43+
def test_reading_specific_table_1a(sample_db_1: Path) -> None:
44+
"""Test reading a specific table and checking its schema."""
45+
df = read_table(sample_db_1, table_name="USysRibbons")
46+
47+
df_expected = pl.DataFrame(
48+
{
49+
"RibbonId": [1, 6],
50+
"RibbonName": ["rbnReportView", "rbnMainMenu"],
51+
"RibbonXML": [
52+
'<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">\r\n <ribbon startFromScratch="true">\r\n <officeMenu>\r\n <button idMso="FileCompactAndRepairDatabase" insertBeforeMso ="FileCloseDatabase" />\r\n <button idMso="FileOpenDatabase" visible="false"/>\r\n <button idMso="FileNewDatabase" visible="false"/>\r\n <splitButton idMso="FileSaveAsMenuAccess" visible="false" />\r\n </officeMenu>\r\n <tabs>\r\n <tab id="tabHome" label="Home">\r\n\r\n <group id="grpClose" label="Close" >\r\n <button idMso="PrintPreviewClose" \r\n size="large" />\r\n </group>\r\n\r\n <group id="grpData" label="Data" >\r\n <button idMso="PublishToPdfOrEdoc"\r\n size="large" />\r\n </group>\r\n\r\n <group id="grpZoom" label="Zoom" >\r\n <splitButton idMso="PrintPreviewZoomMenu"\r\n size="large" />\r\n </group>\r\n\r\n <group id="grpPrint" label="Print" >\r\n <button idMso="PrintDialogAccess"\r\n size="large" />\r\n </group>\r\n\r\n </tab>\r\n </tabs>\r\n </ribbon>\r\n</customUI>', # noqa: E501
53+
'<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">\r\n <ribbon startFromScratch="true">\r\n <officeMenu>\r\n <button idMso="FileCompactAndRepairDatabase" insertBeforeMso ="FileCloseDatabase" />\r\n <button idMso="FileOpenDatabase" visible="false"/>\r\n <button idMso="FileNewDatabase" visible="false"/>\r\n <splitButton idMso="FileSaveAsMenuAccess" visible="false" />\r\n </officeMenu>\r\n <tabs>\r\n <tab id="tabHome" label="Home">\r\n\r\n <group id="grpClose" label="Close" >\r\n <button idMso="FileExit"\r\n label="Exit Database" \r\n imageMso="MasterViewClose" \r\n size="large" />\r\n </group>\r\n\r\n <group id="grpSort" label="Sort" >\r\n <button idMso="SortUp"\r\n size="large"/>\r\n\r\n <button idMso="SortDown"\r\n size="large"/>\r\n\r\n <button idMso="SortRemoveAllSorts" \r\n size="large" />\r\n </group>\r\n\r\n <group id="grpFilter" label="Filter" >\r\n <toggleButton idMso="FilterMenu" \r\n size="large"/>\r\n\r\n <button idMso="FilterClearAllFilters" \r\n size="large"/>\r\n </group>\r\n\r\n <group id="grpReport" label="Reports" >\r\n <button id="cmdViewReport" \r\n label="View Detail Report" \r\n size="large" \r\n imageMso="ViewsReportView" \r\n onAction="Ribbon.OpenDetailReport"/>\r\n </group>\r\n </tab>\r\n\r\n <tab id="tabSystem" label="System">\r\n <group id="grpTables" label="Database Tools" >\r\n <button idMso="DatabaseLinedTableManager"\r\n size="large" />\r\n\r\n <button idMso="FileDatabaseProperties"\r\n size="large" />\r\n </group>\r\n\r\n <group id="grpInfo" label="Information" >\r\n <button id="cmdOpenAbout"\r\n label="About" \r\n size="large" \r\n imageMso="CreateFormBlankForm" \r\n onAction="Ribbon.OpenAboutForm"/>\r\n </group>\r\n </tab>\r\n\r\n </tabs>\r\n </ribbon>\r\n</customUI>', # noqa: E501
54+
],
55+
"RibbonNotes": [None, None],
56+
},
57+
schema={
58+
"RibbonId": pl.Int64,
59+
"RibbonName": pl.String,
60+
"RibbonXML": pl.String,
61+
"RibbonNotes": pl.String,
62+
},
63+
)
64+
assert_frame_equal(df, df_expected)
65+
assert df.schema == df_expected.schema

0 commit comments

Comments
 (0)