Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Tests

on:
push:
branches: [ main, claude/* ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: |
python -m pip install --upgrade pip
pip install -e .

- name: Run tests
run: python -m unittest discover -s tests -p 'test*.py' -v
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ with open('output.nsv', 'w') as f:
writer.write_row(['row2cell1', 'row2cell2', 'row2cell3'])
```

## Running Tests
## Development

### Running Tests

**Important**: Always run tests from the project root to test local code changes (not the installed package):

```bash
cd tests
python -m unittest
python -m unittest discover -s tests -p 'test*.py' -v
```

Alternatively, install in editable mode:

```bash
pip install -e .
```

Must cover
Expand Down
6 changes: 3 additions & 3 deletions nsv/core.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Iterable
from typing import Iterable, List

from .reader import Reader
from .writer import Writer

def load(file_obj) -> list[list[str]]:
def load(file_obj) -> List[List[str]]:
"""Load NSV data from a file-like object."""
return list(Reader(file_obj))

def loads(s: str) -> list[list[str]]:
def loads(s: str) -> List[List[str]]:
"""Load NSV data from a string."""
data = []
row = []
Expand Down
7 changes: 7 additions & 0 deletions tests/samples/escape_edge_cases.nsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\\n
\\\n
\\\\n

\\\\
\n\n

13 changes: 13 additions & 0 deletions tests/samples/trailing_backslash.nsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
yo\
shouln'ta\
be\
doing\
this\

\
or
\
should
\
ya

11 changes: 11 additions & 0 deletions tests/test_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ def test_special_characters(self):
rows = nsv.load(f)
self.assertEqual(SAMPLES_DATA['special_chars'], rows)

def test_trailing_backslash(self):
"""Test handling of special characters in field values."""
expected = [
['yo', 'shouln\'ta', 'be', 'doing', 'this'],
['', 'or', '', 'should', '', 'ya'],
]
file_path = os.path.join(SAMPLES_DIR, 'trailing_backslash.nsv')
with open(file_path, 'r') as f:
rows = nsv.load(f)
self.assertEqual(expected, rows)

# def test_numeric_values(self):
# """Test handling of numeric values."""
# data = [
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
[],
],
'multiline_encoded': [["line1\nline2", "r1c2", "r1c3"], ["anotherline1\nline2\nline3", "r2c2"]],
'escape_edge_cases': [
["\\n", "\\\n", "\\\\n"],
["\\\\", "\n\n"],
],
}


Expand Down