Skip to content

Commit 2d3fad0

Browse files
authored
Add error message if the KOF file contains TABs (#16)
* - Add error message if KOF file contains tabs. - Update packages - Update CHANGES.md - Bump version number to 0.1.1 * - Fix black issue.
1 parent 754fb4f commit 2d3fad0

File tree

6 files changed

+190
-163
lines changed

6 files changed

+190
-163
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Python KOF Parser Package
22

3+
## Version 0.1.1
4+
_2023-11-09_
5+
6+
Add
7+
8+
- Add error message if the KOF file contains TAB characters (not allowed).
9+
310
## Version 0.1.0
411
_2023-10-17_
512

poetry.lock

Lines changed: 161 additions & 161 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ src = ["src", "tests"]
1919

2020
[tool.poetry]
2121
name = "kof-parser"
22-
version = "0.1.0"
22+
version = "0.1.1"
2323
description = "A KOF file parser. Follows Norkart's KOF 2.0 specification from 2005."
2424
license = "MIT"
2525
authors = ["Magnus Mariero <[email protected]>", "Jostein Leira <[email protected]>"]

src/kof_parser/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def tema_code_to_method(self, code: str) -> Optional[str]:
7878

7979
def map_line_to_coordinate_block(self, line: str, result_srid: int) -> Location:
8080
# template_coordinate_block: str = "-05 PPPPPPPPPP KKKKKKKK XXXXXXXX.XXX YYYYYYY.YYY ZZZZ.ZZZ Bk MMMMMMM"
81+
if "\t" in line:
82+
raise ParseError("KOF file contains tabs, please convert to spaces.")
8183

8284
resolved_location = Location(
8385
name=line[4:15].strip(),
@@ -93,6 +95,8 @@ def map_line_to_coordinate_block(self, line: str, result_srid: int) -> Location:
9395

9496
def map_line_to_administrative_block(self, line: str, file_srid: Optional[int]) -> None:
9597
# template_admin_block: str = "-01 OOOOOOOOOOOO DDMMYYYY VVV KKKKKKK KKKK $RVAllllllll OOOOOOOOOOOO"
98+
if "\t" in line:
99+
raise ParseError("KOF file contains tabs, please convert to spaces.")
96100
coordinate_system = line[30:38].strip()
97101
if coordinate_system and not file_srid:
98102
self.file_srid = self.get_srid(int(coordinate_system))

tests/data/kof-with-tabs.kof

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
01 Hopla 09112023 1 22 $11100000000
2+
05 14 7023003.489 598993.753 4.098
3+
05 15 7023231.981 599001.246 4.388
4+
05 2 7023286.401 596889.839 4.231
5+
05 3 7023991.712 596884.579 4.877

tests/test_parse.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from kof_parser import KOFParser
3+
from kof_parser import KOFParser, exceptions
44
from kof_parser.enums import MethodType
55

66

@@ -103,3 +103,14 @@ def test_upload_kof(self, file):
103103

104104
for method in location7.methods:
105105
assert method == MethodType.PZ.value
106+
107+
def test_err_file_containing_tabs(self):
108+
109+
srid = 5110
110+
parser = KOFParser()
111+
112+
with pytest.raises(
113+
exceptions.ParseError,
114+
match="Error parsing KOF file on line 3 - KOF file contains tabs, please convert to spaces.",
115+
):
116+
parser.parse("tests/data/kof-with-tabs.kof", srid)

0 commit comments

Comments
 (0)