Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 68 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,85 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
lib
lib64
__pycache__
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.tox
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask instance folder
instance/

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Spyder project settings
.spyderproject
22 changes: 10 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
language: python
python:
- "2.5"
- "2.6"
- "2.7"
- "pypy"
- "3.3"
- "3.4"
python: 3.5
env:
- TOX_ENV=py26
- TOX_ENV=py27
- TOX_ENV=pypy
- TOX_ENV=py34
- TOX_ENV=py35
- TOX_ENV=lint
install:
- sudo apt-get install clamav-daemon clamav-freshclam clamav-unofficial-sigs
- sudo freshclam --verbose
- sudo service clamav-daemon start
- pip install .
script: python setup.py nosetests
matrix:
allow_failures:
- python: "2.5"
- pip install tox
script: tox -e $TOX_ENV
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To scan a file::

To scan a stream::

>>> from six import BytesIO
>>> from io import BytesIO
>>> cd.instream(BytesIO(clamd.EICAR))
{'stream': ('FOUND', 'Eicar-Test-Signature')}

Expand Down
5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
classifiers = [
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
],
tests_require = (
"nose==1.3.3",
"six==1.7.3",
),
test_suite='nose.collector',
zip_safe=True,
include_package_data=False,
)
6 changes: 4 additions & 2 deletions src/clamd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import base64

scan_response = re.compile(r"^(?P<path>.*): ((?P<virus>.+) )?(?P<status>(FOUND|OK|ERROR))$")
EICAR = base64.b64decode(b'WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5E' \
b'QVJELUFOVElWSVJVUy1URVNU\nLUZJTEUhJEgrSCo=\n')
EICAR = base64.b64decode(
b'WDVPIVAlQEFQWzRcUFpYNTQoUF4pN0NDKTd9JEVJQ0FSLVNUQU5E'
b'QVJELUFOVElWSVJVUy1URVNU\nLUZJTEUhJEgrSCo=\n'
)


class ClamdError(Exception):
Expand Down
50 changes: 19 additions & 31 deletions src/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import clamd
from six import BytesIO
from io import BytesIO
from contextlib import contextmanager
import tempfile
import shutil
import os
import stat

from nose.tools import ok_, eq_, assert_true, raises
import pytest

mine = (stat.S_IREAD | stat.S_IWRITE)
other = stat.S_IROTH
Expand All @@ -26,38 +26,37 @@ def mkdtemp(*args, **kwargs):


class TestUnixSocket(object):
def __init__(self):
self.kwargs = {}
kwargs = {}

def setup(self):
self.cd = clamd.ClamdUnixSocket(**self.kwargs)

def test_ping(self):
assert_true(self.cd.ping())
assert self.cd.ping()

def test_version(self):
ok_(self.cd.version().startswith("ClamAV"))
assert self.cd.version().startswith("ClamAV")

def test_reload(self):
eq_(self.cd.reload(), 'RELOADING')
assert self.cd.reload() == 'RELOADING'

def test_scan(self):
with tempfile.NamedTemporaryFile('wb', prefix="python-clamd") as f:
f.write(clamd.EICAR)
f.flush()
os.fchmod(f.fileno(), (mine | other))
eq_(self.cd.scan(f.name),
{f.name: ('FOUND', 'Eicar-Test-Signature')}
)
expected = {f.name: ('FOUND', 'Eicar-Test-Signature')}

assert self.cd.scan(f.name) == expected

def test_unicode_scan(self):
with tempfile.NamedTemporaryFile('wb', prefix=u"python-clamdλ") as f:
f.write(clamd.EICAR)
f.flush()
os.fchmod(f.fileno(), (mine | other))
eq_(self.cd.scan(f.name),
{f.name: ('FOUND', 'Eicar-Test-Signature')}
)
expected = {f.name: ('FOUND', 'Eicar-Test-Signature')}

assert self.cd.scan(f.name) == expected

def test_multiscan(self):
expected = {}
Expand All @@ -69,31 +68,20 @@ def test_multiscan(self):
expected[f.name] = ('FOUND', 'Eicar-Test-Signature')
os.chmod(d, (mine | other | execute))

eq_(self.cd.multiscan(d), expected)
assert self.cd.multiscan(d) == expected

def test_instream(self):
eq_(
self.cd.instream(BytesIO(clamd.EICAR)),
{'stream': ('FOUND', 'Eicar-Test-Signature')}
)
expected = {'stream': ('FOUND', 'Eicar-Test-Signature')}
assert self.cd.instream(BytesIO(clamd.EICAR)) == expected

def test_insteam_success(self):
eq_(
self.cd.instream(BytesIO(b"foo")),
{'stream': ('OK', None)}
)
assert self.cd.instream(BytesIO(b"foo")) == {'stream': ('OK', None)}


class TestUnixSocketTimeout(TestUnixSocket):
def __init__(self):
self.kwargs = {"timeout": 20}
kwargs = {"timeout": 20}


@raises(clamd.ConnectionError)
def test_cannot_connect():
clamd.ClamdUnixSocket(path="/tmp/404").ping()


# class TestNetworkSocket(TestUnixSocket):
# def setup(self):
# self.cd = clamd.ClamdNetworkSocket()
with pytest.raises(clamd.ConnectionError):
clamd.ClamdUnixSocket(path="/tmp/404").ping()
15 changes: 15 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tox]
envlist = py{26,27,33,34,35}, lint

[testenv]
commands = py.test {posargs}
deps =
pytest==2.8.2

[testenv:lint]
deps =
flake8==2.4.0
commands=flake8 src

[flake8]
max-line-length = 117