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

Code coverage with travis changes #63

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[run]
branch = True
omit =
/usr/*
/home/travis/virtualenv/*

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ a.out
*.out
docstrings/
build/
.tox
*/pyinotify.egg-info/
.coverage
htmlcov/
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
language: python
python:
- "2.4"
- "2.5"
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "pypy"
script: /bin/true
install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 || $TRAVIS_PYTHON_VERSION == 3.3 ]]; then pip install -q coveralls; fi
script:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 || $TRAVIS_PYTHON_VERSION == 3.3 ]]; then coverage run setup.py nosetests; else python setup.py nosetests; fi
after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 || $TRAVIS_PYTHON_VERSION == 3.3 ]]; then coveralls; fi
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Project URL : [http://github.com/seb-m/pyinotify](http://github.com/seb-m/pyinotify)
* Project Wiki : [http://github.com/seb-m/pyinotify/wiki](http://github.com/seb-m/pyinotify/wiki)
* API Documentation: [http://seb-m.github.com/pyinotify](http://seb-m.github.com/pyinotify)
* Test Status : [![tests status](https://secure.travis-ci.org/seb-m/pyinotify.png?branch=master)](https://travis-ci.org/seb-m/pyinotify)
* Coverage Status : [![Coverage Status](https://coveralls.io/repos/seb-m/pyinotify/badge.png?branch=master)](https://coveralls.io/r/seb-m/pyinotify)


## Dependencies
Expand Down
Empty file added python2/__init__.py
Empty file.
102 changes: 102 additions & 0 deletions python2/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import unittest
import os
import pyinotify
import tempfile
import shutil

event_holder = []


class processor(pyinotify.ProcessEvent):
def process_default(self, event):
event_holder.append(event)


class TestPyinotifyEvents(unittest.TestCase):

def setUp(self):
del event_holder[:]
self.watch_directory = tempfile.mkdtemp()
wm = pyinotify.WatchManager()
wm.add_watch(self.watch_directory, pyinotify.ALL_EVENTS)
self.notifier = pyinotify.Notifier(wm, processor())

def tearDown(self):
shutil.rmtree(self.watch_directory)

def _print_events(self):
for e in event_holder:
print("path: %s mask: %s" % ( e.pathname, e.maskname ))

def _get_events(self):
self.notifier.read_events()
self.notifier.process_events()

def _check_events(self, expected):
for i, mask in enumerate(expected):
self.assertEqual(mask, event_holder[i].mask)

def test_create_event(self):
filename = os.path.join(self.watch_directory, "tmp")
open(filename, "w").write("")
self._get_events()
self._check_events([pyinotify.IN_CREATE,
pyinotify.IN_OPEN,
pyinotify.IN_CLOSE_WRITE])

def test_move_event(self):
filename = os.path.join(self.watch_directory, "tmp")
second_dir = tempfile.mkdtemp()
filename2 = os.path.join(second_dir, "tmp")
open(filename, "w").write("")

#Move file out of directory
shutil.move(filename, filename2)
self._get_events()
self.assertEqual(pyinotify.IN_MOVED_FROM, event_holder[-1].mask)

del event_holder[:]

#Move file into directory
shutil.move(filename2, filename)
self._get_events()
self.assertEqual(pyinotify.IN_MOVED_TO, event_holder[-1].mask)

del event_holder[:]

#Move file within directory
filename3 = os.path.join(self.watch_directory, "tmp2")
shutil.move(filename, filename3)
self._get_events()

self._check_events([pyinotify.IN_MOVED_FROM, pyinotify.IN_MOVED_TO])
self.assertEqual(filename, event_holder[0].pathname)
self.assertEqual(filename3, event_holder[1].pathname)

def test_modify_events(self):
filename = os.path.join(self.watch_directory, "tmp")
open(filename, "w").write("")
self._get_events()
del event_holder[:]

open(filename, "a").write("foo")

self._get_events()
self._check_events([pyinotify.IN_OPEN,
pyinotify.IN_MODIFY,
pyinotify.IN_CLOSE_WRITE])

def test_delete_event(self):
filename = os.path.join(self.watch_directory, "tmp")
open(filename, "w").write("")
self._get_events()
del event_holder[:]

os.remove(filename)
self._get_events()

self._print_events()
self._check_events([pyinotify.IN_DELETE])

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions python3/tests.py
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
# Select branch
if sys.version_info >= (3, 0):
package_dir = {'': 'python3'}
extras = {}
else:
package_dir = {'': 'python2'}
extras = { 'test_suite' : 'python2.tests' }


def should_compile_ext_mod():
Expand Down Expand Up @@ -107,4 +109,5 @@ def should_compile_ext_mod():
ext_modules=ext_mod,
py_modules=['pyinotify'],
package_dir=package_dir,
**extras
)
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
envlist = py26, py27, py32, py33, pypy

[testenv]
commands = python setup.py test