11"""
22Test the parsing of full manifests
33"""
4+ import io
45import os
56
6- from pytest import mark
7+ from pytest import mark , raises
8+ from mpd_parser .exceptions import UnicodeDeclaredError , UnknownElementTreeParseError , UnknownValueError
79from mpd_parser .parser import Parser
810
911from tests .conftest import touch_attributes , MANIFESTS_DIR
1012
13+ class DummyFile (io .BytesIO ):
14+ def __enter__ (self ):
15+ return self
16+ def __exit__ (self , exc_type , exc_val , exc_tb ):
17+ self .close ()
18+
19+ def dummy_urlopen (url ):
20+ return DummyFile (b"<MPD></MPD>" )
21+
1122
1223@mark .parametrize ("input_file" , [
1324 "./../manifests/bigBuckBunny-onDemend.mpd" ,
@@ -104,3 +115,49 @@ def test_to_string(input_file):
104115 0 ].range == \
105116 transformed_mpd .periods [0 ].adaptation_sets [0 ].representations [0 ].segment_bases [0 ].initializations [
106117 0 ].range
118+
119+ @mark .parametrize (
120+ "exception,patch_func" ,
121+ [
122+ (UnicodeDeclaredError , lambda : ValueError ("Unicode something" )),
123+ (UnknownValueError , lambda : ValueError ("Some other value error" )),
124+ (UnknownElementTreeParseError , lambda : RuntimeError ("Some runtime error" )),
125+ ]
126+ )
127+ def test_from_string_error_handling (monkeypatch , exception , patch_func ):
128+ def fake_parse (* args , ** kwargs ):
129+ raise patch_func ()
130+ monkeypatch .setattr ("mpd_parser.parser.etree.fromstring" , fake_parse )
131+ with raises (exception ):
132+ Parser .from_string ("<MPD></MPD>" )
133+
134+ @mark .parametrize (
135+ "exception,patch_func" ,
136+ [
137+ (UnicodeDeclaredError , lambda : ValueError ("Unicode something" )),
138+ (UnknownValueError , lambda : ValueError ("Some other value error" )),
139+ (UnknownElementTreeParseError , lambda : RuntimeError ("Some runtime error" )),
140+ ]
141+ )
142+ def test_from_file_error_handling (monkeypatch , exception , patch_func ):
143+ def fake_parse (* args , ** kwargs ):
144+ raise patch_func ()
145+ monkeypatch .setattr ("mpd_parser.parser.etree.parse" , fake_parse )
146+ with raises (exception ):
147+ Parser .from_file ("dummy_file.mpd" )
148+
149+ @mark .parametrize (
150+ "exception,patch_func" ,
151+ [
152+ (UnicodeDeclaredError , lambda : ValueError ("Unicode something" )),
153+ (UnknownValueError , lambda : ValueError ("Some other value error" )),
154+ (UnknownElementTreeParseError , lambda : RuntimeError ("Some runtime error" )),
155+ ]
156+ )
157+ def test_from_url_error_handling (monkeypatch , exception , patch_func ):
158+ def fake_parse (* args , ** kwargs ):
159+ raise patch_func ()
160+ monkeypatch .setattr ("mpd_parser.parser.etree.parse" , fake_parse )
161+ monkeypatch .setattr ("mpd_parser.parser.urlopen" , dummy_urlopen )
162+ with raises (exception ):
163+ Parser .from_url ("http://dummy.url/manifest.mpd" )
0 commit comments