Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add makefile runner for tests #29

Merged
merged 3 commits into from Jan 13, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Create a requirements-test.txt; update the tests to work on Python 2.

The requirements-test.txt file describes what the tests need in order
to run. That's distinct from the requirements to install - and it's
needed because the unittest.mock interface isn't present on Python 2.7,
so we need to use a backport.

This module is then used conditionally in the two tests we currently
have, so that we can run in either version.

The test classes have also had comments added to describe what they're
trying to test and the invariants they assume.
  • Loading branch information
gerph committed Jan 11, 2020
commit 3d05025f6fa8220f7a917ea7528dcb38f41ddc49
@@ -0,0 +1,2 @@
# unittest.mock is present in 3.3 and higher; the mock library provides a backport
mock==3.0.5 ; python_version < '3.3'
@@ -1,12 +1,25 @@
import unittest
import zipfile
import io
from unittest.mock import patch

import pythonfuzz
try:
from unittest.mock import patch
except ImportError:
# Python 2 backport of mock
from mock import patch

import pythonfuzz.fuzzer


class TestFindCrash(unittest.TestCase):
def test_find_crash(self):
"""
Tests that when an Exception occurs in the fuzz function, we detect this.
Requires that the Fuzzer's configuration causes it to stop when an exception
is detected, and that the fuzzer will generate an invalid zip file.
Detects the exception implicitly by the fact that a logger call was made.
"""
def fuzz(buf):
f = io.BytesIO(buf)
z = zipfile.ZipFile(f)
@@ -1,12 +1,22 @@
import unittest
import zipfile
import io
from unittest.mock import patch

import pythonfuzz
try:
from unittest.mock import patch
except ImportError:
# Python 2 backport of mock
from mock import patch

import pythonfuzz.fuzzer


class TestFindCrash(unittest.TestCase):
def test_find_crash(self):
"""
Tests that when no Exception occurs in the fuzz function, we exit without error.
Detects the exception implicitly by the fact that a logger call was made with
particular text.
"""
def fuzz(buf):
return True

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.