Skip to content

Commit 74d7fe0

Browse files
committed
Tests: move test_zip.py from private repo; slightly modified from the original version on DSS-Python
1 parent 736d4ad commit 74d7fe0

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/test_zip.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import pytest
2+
from altdss import altdss as DSS, DSSException
3+
try:
4+
from ._settings import ZIP_FN
5+
except ImportError:
6+
from _settings import ZIP_FN
7+
8+
9+
def test_zip_redirect():
10+
with pytest.raises(DSSException):
11+
DSS.ZIP.Redirect('13Bus/IEEE13Nodeckt.dss')
12+
13+
DSS.ZIP.Close()
14+
DSS.ZIP.Open(ZIP_FN)
15+
DSS.ZIP.Redirect('13Bus/IEEE13Nodeckt.dss')
16+
DSS.ZIP.Close()
17+
assert DSS.Name == 'ieee13nodeckt'
18+
assert DSS.NumNodes == 41
19+
assert DSS.NumBuses == 16
20+
21+
22+
def test_zip_contains():
23+
with pytest.raises(DSSException):
24+
assert 'before open' in DSS.ZIP
25+
26+
DSS.ZIP.Open(ZIP_FN)
27+
assert '13Bus/README.txt' in DSS.ZIP
28+
assert '13Bus/some/wrong/entry.txt' not in DSS.ZIP
29+
DSS.ZIP.Close()
30+
31+
32+
def test_zip_exists():
33+
with pytest.raises(DSSException):
34+
DSS.ZIP.Open('something1/something2/something3.zip')
35+
36+
def test_zip_filelist():
37+
DSS.ZIP.Open(ZIP_FN)
38+
assert set(DSS.ZIP.List()) == {'13Bus/', '13Bus/IEEE13Node_BusXY.csv', '13Bus/IEEE13Nodeckt.dss', '13Bus/IEEELineCodes.DSS', '13Bus/README.txt'}
39+
assert DSS.ZIP.List('.*/RE.*') == ['13Bus/README.txt']
40+
41+
def test_zip_extract():
42+
DSS.ZIP.Open(ZIP_FN)
43+
44+
fragment = b'This is a copy of the 13Bus folder which is distributed with OpenDSS.'
45+
readme_txt = DSS.ZIP.Extract('13Bus/README.txt')
46+
assert readme_txt.startswith(fragment)
47+
48+
assert DSS.ZIP['13Bus/README.txt'].startswith(readme_txt)
49+

0 commit comments

Comments
 (0)