Skip to content

Commit 7999856

Browse files
committed
Add tests for fdscan()
1 parent 91f3e3f commit 7999856

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/tests/test_api.py

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import shutil
99
import os
1010
import stat
11+
import sys
12+
try:
13+
import _multiprocessing
14+
have_multiprocessing_sendfd = hasattr(_multiprocessing, 'sendfd') and callable(_multiprocessing.sendfd)
15+
except ImportError:
16+
have_multiprocessing_sendfd = False
1117

1218
import pytest
1319

@@ -77,6 +83,24 @@ def test_instream(self):
7783
def test_insteam_success(self):
7884
assert self.cd.instream(BytesIO(b"foo")) == {'stream': ('OK', None)}
7985

86+
@pytest.mark.skipif(sys.version_info[0] < 3 and not have_multiprocessing_sendfd,
87+
reason="For Python 2.x, _multiprocessing.sendfd() is required for this test")
88+
def test_fdscan(self):
89+
with tempfile.NamedTemporaryFile('wb', prefix="python-clamd") as f:
90+
f.write(clamd.EICAR)
91+
f.flush()
92+
expected = {f.name: ('FOUND', 'Eicar-Test-Signature')}
93+
assert self.cd.fdscan(f.name, f.fileno()) == expected
94+
95+
@pytest.mark.skipif(sys.version_info[0] < 3 and not have_multiprocessing_sendfd,
96+
reason="For Python 2.x, _multiprocessing.sendfd() is required for this test")
97+
def test_fdscan_success(self):
98+
with tempfile.NamedTemporaryFile('wb', prefix="python-clamd") as f:
99+
f.write(b"foo")
100+
f.flush()
101+
expected = {f.name: ('OK', None)}
102+
assert self.cd.fdscan(f.name, f.fileno()) == expected
103+
80104

81105
class TestUnixSocketTimeout(TestUnixSocket):
82106
kwargs = {"timeout": 20}

0 commit comments

Comments
 (0)