22# -*- coding: utf-8 -*-
33from __future__ import unicode_literals
44import clamd
5- from six import BytesIO
5+ from io import BytesIO
66from contextlib import contextmanager
77import tempfile
88import shutil
99import os
1010import stat
1111
12- from nose . tools import ok_ , eq_ , assert_true , raises
12+ import pytest
1313
1414mine = (stat .S_IREAD | stat .S_IWRITE )
1515other = stat .S_IROTH
@@ -26,38 +26,37 @@ def mkdtemp(*args, **kwargs):
2626
2727
2828class TestUnixSocket (object ):
29- def __init__ (self ):
30- self .kwargs = {}
29+ kwargs = {}
3130
3231 def setup (self ):
3332 self .cd = clamd .ClamdUnixSocket (** self .kwargs )
3433
3534 def test_ping (self ):
36- assert_true ( self .cd .ping () )
35+ assert self .cd .ping ()
3736
3837 def test_version (self ):
39- ok_ ( self .cd .version ().startswith ("ClamAV" ) )
38+ assert self .cd .version ().startswith ("ClamAV" )
4039
4140 def test_reload (self ):
42- eq_ ( self .cd .reload (), 'RELOADING' )
41+ assert self .cd .reload () == 'RELOADING'
4342
4443 def test_scan (self ):
4544 with tempfile .NamedTemporaryFile ('wb' , prefix = "python-clamd" ) as f :
4645 f .write (clamd .EICAR )
4746 f .flush ()
4847 os .fchmod (f .fileno (), (mine | other ))
49- eq_ ( self . cd . scan ( f .name ),
50- { f . name : ( 'FOUND' , 'Eicar-Test-Signature' )}
51- )
48+ expected = { f .name : ( 'FOUND' , 'Eicar-Test-Signature' )}
49+
50+ assert self . cd . scan ( f . name ) == expected
5251
5352 def test_unicode_scan (self ):
5453 with tempfile .NamedTemporaryFile ('wb' , prefix = u"python-clamdλ" ) as f :
5554 f .write (clamd .EICAR )
5655 f .flush ()
5756 os .fchmod (f .fileno (), (mine | other ))
58- eq_ ( self . cd . scan ( f .name ),
59- { f . name : ( 'FOUND' , 'Eicar-Test-Signature' )}
60- )
57+ expected = { f .name : ( 'FOUND' , 'Eicar-Test-Signature' )}
58+
59+ assert self . cd . scan ( f . name ) == expected
6160
6261 def test_multiscan (self ):
6362 expected = {}
@@ -69,31 +68,20 @@ def test_multiscan(self):
6968 expected [f .name ] = ('FOUND' , 'Eicar-Test-Signature' )
7069 os .chmod (d , (mine | other | execute ))
7170
72- eq_ ( self .cd .multiscan (d ), expected )
71+ assert self .cd .multiscan (d ) == expected
7372
7473 def test_instream (self ):
75- eq_ (
76- self .cd .instream (BytesIO (clamd .EICAR )),
77- {'stream' : ('FOUND' , 'Eicar-Test-Signature' )}
78- )
74+ expected = {'stream' : ('FOUND' , 'Eicar-Test-Signature' )}
75+ assert self .cd .instream (BytesIO (clamd .EICAR )) == expected
7976
8077 def test_insteam_success (self ):
81- eq_ (
82- self .cd .instream (BytesIO (b"foo" )),
83- {'stream' : ('OK' , None )}
84- )
78+ assert self .cd .instream (BytesIO (b"foo" )) == {'stream' : ('OK' , None )}
8579
8680
8781class TestUnixSocketTimeout (TestUnixSocket ):
88- def __init__ (self ):
89- self .kwargs = {"timeout" : 20 }
82+ kwargs = {"timeout" : 20 }
9083
9184
92- @raises (clamd .ConnectionError )
9385def test_cannot_connect ():
94- clamd .ClamdUnixSocket (path = "/tmp/404" ).ping ()
95-
96-
97- # class TestNetworkSocket(TestUnixSocket):
98- # def setup(self):
99- # self.cd = clamd.ClamdNetworkSocket()
86+ with pytest .raises (clamd .ConnectionError ):
87+ clamd .ClamdUnixSocket (path = "/tmp/404" ).ping ()
0 commit comments