66import os
77import os .path
88import platform
9- import sys
109
10+ import pytest
1111import mss
1212import mss .tools
13- from mss .base import MSSMixin
13+ from mss .base import MSSBase
1414from mss .exception import ScreenShotError
1515from mss .screenshot import ScreenShot
1616
17- import pytest
18-
1917
20- PY3 = sys .version [0 ] > "2"
21-
22-
23- class MSS0 (MSSMixin ):
18+ class MSS0 (MSSBase ):
2419 """ Nothing implemented. """
2520
2621 pass
2722
2823
29- class MSS1 (MSSMixin ):
30- """ Emulate no monitors . """
24+ class MSS1 (MSSBase ):
25+ """ Only `grab()` implemented . """
3126
32- @property
33- def monitors (self ):
34- return []
27+ def grab (self , monitor ):
28+ pass
3529
3630
37- class MSS2 (MSSMixin ):
38- """ Emulate one monitor. """
31+ class MSS2 (MSSBase ):
32+ """ Only ` monitor` implemented . """
3933
4034 @property
4135 def monitors (self ):
42- return [{"top" : 0 , "left" : 0 , "width" : 10 , "height" : 10 }]
43-
36+ return []
4437
45- def test_incomplete_class ():
46- # `monitors` property not implemented
47- with pytest .raises (NotImplementedError ):
48- for filename in MSS0 ().save ():
49- assert os .path .isfile (filename )
5038
51- # `monitors` property is empty
52- with pytest . raises ( ScreenShotError ):
53- for filename in MSS1 (). save ( ):
54- assert os . path . isfile ( filename )
39+ @ pytest . mark . parametrize ( "cls" , [ MSS0 , MSS1 , MSS2 ])
40+ def test_incomplete_class ( cls ):
41+ with pytest . raises ( TypeError ):
42+ cls ( )
5543
56- # `grab()` not implemented
57- sct = MSS2 ()
58- with pytest .raises (NotImplementedError ):
59- sct .grab (sct .monitors [0 ])
6044
61- # Bad monitor
45+ def test_bad_monitor ( sct ):
6246 with pytest .raises (ScreenShotError ):
6347 sct .grab (sct .shot (mon = 222 ))
6448
@@ -79,18 +63,15 @@ def test_repr(sct, pixel_ratio):
7963def test_factory (monkeypatch ):
8064 # Current system
8165 with mss .mss () as sct :
82- assert isinstance (sct , MSSMixin )
66+ assert isinstance (sct , MSSBase )
8367
8468 # Unknown
8569 monkeypatch .setattr (platform , "system" , lambda : "Chuck Norris" )
8670 with pytest .raises (ScreenShotError ) as exc :
8771 mss .mss ()
8872 monkeypatch .undo ()
8973
90- if not PY3 :
91- error = exc .value [0 ]
92- else :
93- error = exc .value .args [0 ]
74+ error = exc .value .args [0 ]
9475 assert error == "System 'chuck norris' not (yet?) implemented."
9576
9677
0 commit comments