Permalink
Browse files

working on linux

  • Loading branch information...
1 parent cb75dec commit 50628fa4022fd98331ed8577386ebc83df52b9a1 martinrusev committed Aug 23, 2011
View
3 README.rst
@@ -39,6 +39,9 @@ download the tarball and run ``python setup.py install``
Usage
=========
+::
+
+ ./manage.py autotest
View
73 autotest/management/commands/autotest.py
@@ -1,73 +0,0 @@
-import time
-from watchdog.observers import Observer
-from watchdog.events import PatternMatchingEventHandler
-from django.core.management.base import BaseCommand
-from os import chdir
-from django.conf import settings
-from subprocess import Popen, PIPE, call
-from os.path import abspath, dirname, join, split
-
-def get_autotest_path():
-
- CURRENT_PATH = abspath(dirname(__file__))
- AUTOTEST_PATH = abspath(join(CURRENT_PATH, '..'))
-
- return AUTOTEST_PATH
-
-
-class AutotestEventHandler(PatternMatchingEventHandler):
-
-
- def run_test_suite(self):
-
-
- chdir(settings.PROJECT_ROOT)
- result = Popen(['./manage.py', 'autotestrunner'], stdout=PIPE, stderr=PIPE, close_fds=True).communicate()
-
- title = ''
- content = ''
- for line in result:
- split_lines = line.split('\n')
- for l in split_lines:
- if l.startswith('Ran'):
- title = l
- if l.startswith('OK') or l.startswith('FAIL'):
- content = l
-
- call(['/usr/bin/python',
- '{0}notifications.py'.format(get_autotest_path()),
- '--title={0}'.format(title),
- '--content={0}'.format(content)]
- )
-
-
- def on_modified(self, event):
- path_to_file, filename = split(event.src_path)
- self.run_test_suite()
-
-
-class Command(BaseCommand):
- option_list = BaseCommand.option_list + (
- )
- help = 'Runs the test suite when a tests file is saved'
- args = '[appname ...]'
-
- requires_model_validation = False
-
- def handle(self, *args, **options):
- self.event_handler = AutotestEventHandler(patterns=['*.py'],ignore_directories=True)
- self.run()
-
- def run(self):
- app_path = settings.PROJECT_ROOT
-
- observer = Observer()
- observer.schedule(self.event_handler, app_path, recursive=True)
- observer.start()
- try:
- while True:
- time.sleep(1)
- except KeyboardInterrupt:
- observer.stop()
- observer.join()
-
View
BIN autotest/management/commands/autotest.pyc
Binary file not shown.
View
BIN autotest/management/commands/autotestrunner.pyc
Binary file not shown.
View
13 autotest/notifications.py
@@ -1,13 +0,0 @@
-import sys
-import pynotify
-import getopt
-
-if __name__ == '__main__':
-
- args = sys.argv[1:]
- optlist,args = getopt.getopt(args, "tc:d", ['title=', 'content='])
-
- title = optlist[0][1]
- content = optlist[1][1]
- n = pynotify.Notification(title, content)
- n.show()
View
0 autotest/management/commands/__init__.py → exampleapp/__init__.py
File renamed without changes.
View
BIN exampleapp/__init__.pyc
Binary file not shown.
View
14 exampleapp/manage.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
39 exampleapp/settings.py
@@ -0,0 +1,39 @@
+from os.path import abspath, dirname
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'autotest', # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ }
+}
+
+TIME_ZONE = 'Europe/London'
+LANGUAGE_CODE = 'en-gb'
+
+SECRET_KEY = 'z5o=jpfkj!blgm-f-_jnfnm&2y0gz$hb64ap(cjj1g!t!+*&2='
+
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+)
+
+
+ROOT_URLCONF = 'exampleapp.urls'
+
+
+INSTALLED_APPS = (
+ 'django.contrib.staticfiles',
+ 'autotest'
+ )
+
+
+PROJECT_ROOT = abspath(dirname(__file__))
+
+
View
BIN exampleapp/settings.pyc
Binary file not shown.
View
5 exampleapp/tests/example_test.py
@@ -0,0 +1,5 @@
+import unittest
+
+class MyFuncTestCase(unittest.TestCase):
+ def testBasic(self):
+ self.assertEqual(1,2)
View
6 exampleapp/urls.py
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import patterns, include, url
+
+urlpatterns = patterns('',
+
+)
+
View
7 setup.py
@@ -1,6 +1,9 @@
from setuptools import setup, find_packages
import os
+SRC_DIR = 'src'
+
+
def read(filename):
return open(os.path.join(os.path.dirname(__file__), filename)).read()
@@ -22,8 +25,8 @@ def read(filename):
author_email='martinrusev@live.com',
url='https://github.com/martinrusev/django-autotest',
license='BSD',
- packages=find_packages(),
+ package_dir={'': SRC_DIR},
+ packages=find_packages(SRC_DIR),
zip_safe=False,
install_requires=['setuptools','watchdog',],
- include_package_data=True,
)
View
0 autotest/management/__init__.py → src/__init__.py
File renamed without changes.
View
0 autotest/__init__.py → src/autotest/__init__.py
File renamed without changes.
View
0 autotest/__init__.pyc → src/autotest/__init__.pyc
File renamed without changes.
View
0 src/autotest/management/__init__.py
No changes.
View
0 autotest/management/__init__.pyc → src/autotest/management/__init__.pyc
File renamed without changes.
View
0 src/autotest/management/commands/__init__.py
No changes.
View
0 autotest/management/commands/__init__.pyc → ...autotest/management/commands/__init__.pyc
File renamed without changes.
View
110 src/autotest/management/commands/autotest.py
@@ -0,0 +1,110 @@
+import time
+from watchdog.observers import Observer
+from watchdog.events import FileSystemEventHandler
+from django.core.management.base import BaseCommand
+from os import chdir
+from django.conf import settings
+from subprocess import Popen, PIPE, call
+from os.path import split, dirname, join, abspath
+import os.path
+import logging
+
+def get_autotest_path():
+
+ CURRENT_PATH = abspath(dirname(__file__))
+ AUTOTEST_PATH = abspath(join(CURRENT_PATH, '..'))
+
+ return AUTOTEST_PATH
+
+def absolute_path(path):
+
+ return os.path.abspath(os.path.normpath(path))
+
+
+class LoggingEventHandler(FileSystemEventHandler):
+
+
+ def run_test_suite(self):
+
+ chdir(settings.PROJECT_ROOT)
+ result = Popen(['./manage.py', 'autotestrunner'], stdout=PIPE, stderr=PIPE, close_fds=True).communicate()
+
+ title = ''
+ content = ''
+ for line in result:
+ split_lines = line.split('\n')
+ for l in split_lines:
+ if l.startswith('Ran'):
+ title = l
+ if l.startswith('OK') or l.startswith('FAIL'):
+ content = l
+
+ print title
+ print content
+ os.system('./autotest/notify.sh "{0}" "{1}" '.format(title, content))
+
+
+ def on_modified(self, event):
+ super(LoggingEventHandler, self).on_modified(event)
+ path_to_file, filename = split(event.src_path)
+
+ self.run_test_suite()
+
+
+class AutotestEventHandler(LoggingEventHandler):
+
+ def run_test_suite(self):
+
+ chdir(settings.PROJECT_ROOT)
+ result = Popen(['./manage.py', 'autotestrunner'], stdout=PIPE, stderr=PIPE, close_fds=True).communicate()
+
+ title = ''
+ content = ''
+ for line in result:
+ split_lines = line.split('\n')
+ for l in split_lines:
+ if l.startswith('Ran'):
+ title = l
+ if l.startswith('OK') or l.startswith('FAIL'):
+ content = l
+
+ call(['/usr/bin/python',
+ '{0}notifications.py'.format(get_autotest_path()),
+ '--title={0}'.format(title),
+ '--content={0}'.format(content)]
+ )
+
+
+ def on_modified(self, event):
+ super(AutotestEventHandler, self).on_modified(event)
+ print 'test'
+ path_to_file, filename = split(event.src_path)
+ self.run_test_suite()
+
+
+class Command(BaseCommand):
+ option_list = BaseCommand.option_list + ()
+ help = 'Runs the test suite when a tests file is saved'
+ args = '[appname ...]'
+
+ requires_model_validation = False
+
+ def handle(self, *args, **options):
+ logging.basicConfig(level=logging.INFO,
+ format='%(asctime)s - %(message)s',
+ datefmt='%Y-%m-%d %H:%M:%S')
+ #handler = AutotestEventHandler()
+ handler = LoggingEventHandler()
+
+ app_path = absolute_path(settings.PROJECT_ROOT)
+
+ observer = Observer()
+ observer.schedule(handler, path=app_path, recursive=True)
+ observer.start()
+ try:
+ while True:
+ time.sleep(1)
+ except KeyboardInterrupt:
+ observer.stop()
+ observer.join()
+
View
BIN src/autotest/management/commands/autotest.pyc
Binary file not shown.
View
3 ...est/management/commands/autotestrunner.py → ...est/management/commands/autotestrunner.py
@@ -3,7 +3,8 @@
def get_runner(settings):
- test_path = settings.AUTOTEST_RUNNER.split('.')
+ runner = 'autotest.testrunner.AutotestSuiteRunner'
+ test_path = runner.split('.')
# Allow for Python 2.5 relative paths
if len(test_path) > 1:
test_module_name = '.'.join(test_path[:-1])
View
BIN src/autotest/management/commands/autotestrunner.pyc
Binary file not shown.
View
10 src/autotest/notify.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Displays a desktop notification using Growl (OS X) or libnotify (Linux).
+
+title=$1
+message=$2
+icon=$3
+
+
+which growlnotify && growlnotify --image "$icon" -m "$message" "$title" || \
+which notify-send && notify-send "$title" "$message" -i "$icon"
View
0 autotest/testrunner.py → src/autotest/testrunner.py
File renamed without changes.
View
BIN src/autotest/testrunner.pyc
Binary file not shown.

0 comments on commit 50628fa

Please sign in to comment.