From d221b9a9d5ae513baee77a9ca1e35fd5e596c458 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Sat, 16 Dec 2023 23:08:47 +0100 Subject: [PATCH] Survex3D encoding and version tests --- .gitattributes | 9 +++++++++ extensions/survex.py | 2 +- tests/data/3d/umlaut-latin1-v3.3d | Bin 0 -> 159 bytes tests/data/3d/umlaut-latin1-v4.3d | Bin 0 -> 159 bytes tests/data/3d/umlaut-latin1-v5.3d | Bin 0 -> 159 bytes tests/data/3d/umlaut-latin1-v6.3d | Bin 0 -> 159 bytes tests/data/3d/umlaut-latin1-v7.3d | Bin 0 -> 159 bytes tests/data/3d/umlaut-latin1-v8.3d | Bin 0 -> 140 bytes tests/data/3d/umlaut-utf8-v3.3d | Bin 0 -> 160 bytes tests/data/3d/umlaut-utf8-v4.3d | Bin 0 -> 160 bytes tests/data/3d/umlaut-utf8-v5.3d | Bin 0 -> 160 bytes tests/data/3d/umlaut-utf8-v6.3d | Bin 0 -> 160 bytes tests/data/3d/umlaut-utf8-v7.3d | Bin 0 -> 160 bytes tests/data/3d/umlaut-utf8-v8.3d | Bin 0 -> 141 bytes tests/data/make-3d.sh | 9 +++++++++ tests/data/umlaut-latin1.svx | 5 +++++ tests/data/umlaut-utf8.svx | 5 +++++ tests/test_survex.py | 13 +++++++++++++ 18 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .gitattributes create mode 100644 tests/data/3d/umlaut-latin1-v3.3d create mode 100644 tests/data/3d/umlaut-latin1-v4.3d create mode 100644 tests/data/3d/umlaut-latin1-v5.3d create mode 100644 tests/data/3d/umlaut-latin1-v6.3d create mode 100644 tests/data/3d/umlaut-latin1-v7.3d create mode 100644 tests/data/3d/umlaut-latin1-v8.3d create mode 100644 tests/data/3d/umlaut-utf8-v3.3d create mode 100644 tests/data/3d/umlaut-utf8-v4.3d create mode 100644 tests/data/3d/umlaut-utf8-v5.3d create mode 100644 tests/data/3d/umlaut-utf8-v6.3d create mode 100644 tests/data/3d/umlaut-utf8-v7.3d create mode 100644 tests/data/3d/umlaut-utf8-v8.3d create mode 100644 tests/data/make-3d.sh create mode 100644 tests/data/umlaut-latin1.svx create mode 100644 tests/data/umlaut-utf8.svx create mode 100644 tests/test_survex.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ec5715 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# https://help.github.com/articles/dealing-with-line-endings/ + +* text=auto eol=lf +*.py text +*.svg text +*.th2 text + +*.svx text +*.3d binary diff --git a/extensions/survex.py b/extensions/survex.py index bfd1392..c317102 100644 --- a/extensions/survex.py +++ b/extensions/survex.py @@ -253,7 +253,7 @@ def __init__(self, filename=None, flags_leg_exclude=0): self.flags_leg_exclude = flags_leg_exclude if filename is None: pass - elif isinstance(filename, basestring): + elif isinstance(filename, basestring) or hasattr(filename, "__fspath__"): self.load(filename) else: # assume iterable with stations diff --git a/tests/data/3d/umlaut-latin1-v3.3d b/tests/data/3d/umlaut-latin1-v3.3d new file mode 100644 index 0000000000000000000000000000000000000000..e149403a87e0f3c77391916a2ef8a9f36e525768 GIT binary patch literal 159 zcmWG8Eh>9$w&wvCP!0ZaBNCQI%BLf4B=fr4?%w=$5GyDe01vqt2LJ#7 literal 0 HcmV?d00001 diff --git a/tests/data/3d/umlaut-latin1-v4.3d b/tests/data/3d/umlaut-latin1-v4.3d new file mode 100644 index 0000000000000000000000000000000000000000..8132dd209ce79f2138f7732cf77338bf351a1763 GIT binary patch literal 159 zcmWG8Eh>9$w&wvCP!0ZaBNCQI%BLf4B=fr4?%w=$5GyDe01!eM2mk;8 literal 0 HcmV?d00001 diff --git a/tests/data/3d/umlaut-latin1-v5.3d b/tests/data/3d/umlaut-latin1-v5.3d new file mode 100644 index 0000000000000000000000000000000000000000..ae15e6ad16f511b50872b9801afce42b49bd31cb GIT binary patch literal 159 zcmWG8Eh>9$w&wvCP!0ZaBNCQI%BLf4B=fr4?%w=$5GyDe01(R=2><{9 literal 0 HcmV?d00001 diff --git a/tests/data/3d/umlaut-latin1-v6.3d b/tests/data/3d/umlaut-latin1-v6.3d new file mode 100644 index 0000000000000000000000000000000000000000..8377321c41433cb5b1e5945c1678912b289e6cb3 GIT binary patch literal 159 zcmWG8Eh>9$w&wvCP!0ZaBNCQI%BLf4B=fr4?%w=$5GyDe01;Ff3IG5A literal 0 HcmV?d00001 diff --git a/tests/data/3d/umlaut-latin1-v7.3d b/tests/data/3d/umlaut-latin1-v7.3d new file mode 100644 index 0000000000000000000000000000000000000000..2f38a91d44d6efb37d55db361c555c3a9349a8ca GIT binary patch literal 159 zcmWG8Eh>9$w&wvCP!0ZaBNCQI%BLf4B=fr4?%w=$5GyDe01@383jhEB literal 0 HcmV?d00001 diff --git a/tests/data/3d/umlaut-latin1-v8.3d b/tests/data/3d/umlaut-latin1-v8.3d new file mode 100644 index 0000000000000000000000000000000000000000..6459f3944000b68fa926a0da5435288be4ff9ddb GIT binary patch literal 140 zcmWG8Eh$)4$H>6Q zSkKT%&(KW4$k@uj(8}0Y!Pzy0i=P1rG=SL^P>}|P5Jm$)4$H>6Q zSkKT%&(KW4$k@uj(8}0Y!Pzy0i=P1rG=SL^P>}|P5Jm$)4$H>6Q zSkKT%&(KW4$k@uj(8}0Y!Pzy0i=P1rG=SL^P>}|P5Jm$)4$H>6Q zSkKT%&(KW4$k@uj(8}0Y!Pzy0i=P1rG=SL^P>}|P5Jm$)4$H>6Q zSkKT%&(KW4$k@uj(8}0Y!Pzy0i=P1rG=SL^P>}|P5Jm6;P3c5Jm*2iP0E^D`n+a literal 0 HcmV?d00001 diff --git a/tests/data/make-3d.sh b/tests/data/make-3d.sh new file mode 100644 index 0000000..430b23e --- /dev/null +++ b/tests/data/make-3d.sh @@ -0,0 +1,9 @@ +#!/bin/sh +for enc in latin1 utf8; do + for v in 3 4 5 6 7 8; do + out="3d/umlaut-$enc-v$v.3d" + if [[ ! -f "$out" ]]; then + cavern -v $v -o "$out" umlaut-$enc.svx + fi + done +done diff --git a/tests/data/umlaut-latin1.svx b/tests/data/umlaut-latin1.svx new file mode 100644 index 0000000..dc2e119 --- /dev/null +++ b/tests/data/umlaut-latin1.svx @@ -0,0 +1,5 @@ +*title "Höhle mit Umlaut" + +*data normal from to length clino compass +1 2 1.2 +0 000 +2 3 3.4 +0 090 diff --git a/tests/data/umlaut-utf8.svx b/tests/data/umlaut-utf8.svx new file mode 100644 index 0000000..2df582b --- /dev/null +++ b/tests/data/umlaut-utf8.svx @@ -0,0 +1,5 @@ +*title "Höhle mit Umlaut" + +*data normal from to length clino compass +1 2 1.2 +0 000 +2 3 3.4 +0 090 diff --git a/tests/test_survex.py b/tests/test_survex.py new file mode 100644 index 0000000..470a122 --- /dev/null +++ b/tests/test_survex.py @@ -0,0 +1,13 @@ +import survex as m + +from pathlib import Path + +TESTS_DATA = Path(__file__).resolve().parent / "data" + + +def test_Survex3D_umlaut(): + for path3d in (TESTS_DATA / "3d").glob("umlaut-*.3d"): + s = m.Survex3D(path3d) + assert s.length() == 460.0 + assert list(s.sortedlabels()) == ["1", "2", "3"] + assert s.title == "Höhle mit Umlaut"