File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change 2
2
unicode_literals )
3
3
4
4
import six
5
-
5
+ from six import BytesIO
6
6
import glob
7
7
import os
8
-
8
+ import shutil
9
9
import numpy as np
10
+ import pytest
10
11
11
12
from matplotlib .testing .decorators import image_comparison
12
13
from matplotlib import pyplot as plt
13
14
import matplotlib .cm as cm
14
-
15
+ import tempfile
15
16
import sys
16
17
on_win = (sys .platform == 'win32' )
17
18
@@ -46,3 +47,30 @@ def test_imread_png_uint16():
46
47
47
48
assert (img .dtype == np .uint16 )
48
49
assert np .sum (img .flatten ()) == 134184960
50
+
51
+
52
+ def test_truncated_file ():
53
+ d = tempfile .mkdtemp ()
54
+ fname = os .path .join (d , 'test.png' )
55
+ fname_t = os .path .join (d , 'test_truncated.png' )
56
+ plt .savefig (fname )
57
+ with open (fname , 'rb' ) as fin :
58
+ buf = fin .read ()
59
+ with open (fname_t , 'wb' ) as fout :
60
+ fout .write (buf [:20 ])
61
+
62
+ with pytest .raises (Exception ):
63
+ plt .imread (fname_t )
64
+
65
+ shutil .rmtree (d )
66
+
67
+
68
+ def test_truncated_buffer ():
69
+ b = BytesIO ()
70
+ plt .savefig (b )
71
+ b .seek (0 )
72
+ b2 = BytesIO (b .read (20 ))
73
+ b2 .seek (0 )
74
+
75
+ with pytest .raises (Exception ):
76
+ plt .imread (b2 )
You can’t perform that action at this time.
0 commit comments