Skip to content

Commit

Permalink
Finished pylinting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaur Nasibov committed Dec 18, 2012
1 parent 5ca94de commit 9e30694
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 68 deletions.
8 changes: 2 additions & 6 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ load-plugins=
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
disable=I0011,C0111,C0103,R0903,W0142,R0904
disable=I0011,C0111,C0103,R0903,W0142,R0904,I0013
# C0111: Missing docstring
# C0103: Invalid name XXX (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
# R0903: Too few public methods
# W0142: Used * or ** magic
# R0904: Too many public methods

# C0103,W0212,R0903,R0914,W0142,W0212,W0603,W0402

# W0603: Using the global statement in loader for the _classes cache
# W0402: Uses of a deprecated module 'string' in util.py, which is NOT deprecated at all!
# I0013: 1,0: Ignoring entire file

[REPORTS]

Expand Down
2 changes: 1 addition & 1 deletion kaylee/contrib/frontends/django_frontend/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import patterns, url
from kaylee.controller import app_name_pattern
from kaylee.node import node_id_pattern

Expand Down
2 changes: 2 additions & 0 deletions kaylee/contrib/frontends/django_frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def register_node(request):
reg_data = kl.register(request.META['REMOTE_ADDR'])
return json_response(reg_data)

#pylint: disable-msg=W0613
#W0613: Unused argument 'request'
@csrf_exempt
@require_http_methods(["POST"])
def subscribe_node(request, app_name, node_id):
Expand Down
1 change: 1 addition & 0 deletions kaylee/contrib/frontends/flask_frontend/flask_frontend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-

from flask import Blueprint, request, Response
from kaylee import kl

Expand Down
39 changes: 23 additions & 16 deletions kaylee/testsuite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
#pylint: disable-msg=W0703,W0212
#W0703: Catching too general exception Exception
#W0212: Access to a protected member a client class
#W0231: __init__ method from base class 'TestLoader' is not called

###
import os
import sys
import unittest
Expand All @@ -21,11 +27,11 @@ class KayleeTest(unittest.TestCase):


def load_tests(test_cases):
suite = unittest.TestSuite()
tsuite = unittest.TestSuite()
for tcase in test_cases:
loaded_suite = unittest.defaultTestLoader.loadTestsFromTestCase(tcase)
suite.addTest(loaded_suite)
return suite
tsuite.addTest(loaded_suite)
return tsuite


def suite():
Expand All @@ -34,7 +40,7 @@ def suite():
in case you want to test that monkeypatches to Kaylee do not
break it.
"""
suite = unittest.TestSuite()
tsuite = unittest.TestSuite()
cdir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, cdir)
for fname in os.listdir(cdir):
Expand All @@ -44,27 +50,27 @@ def suite():
try:
mod = import_module(modname)
if hasattr(mod, 'kaylee_suite'):
suite.addTest(mod.kaylee_suite)
tsuite.addTest(mod.kaylee_suite)
except Exception as e:
log.critical('Error importing module {}: {}'.format(modname, e))
sys.exit(0)
return suite
return tsuite


def find_all_tests(root_suite):
"""Yields all the tests and their names from a given suite."""
suites = [root_suite]
while suites:
suite = suites.pop()
tsuite = suites.pop()
try:
# not that suite is iterable, thus every sub-suite from suite
# is appended to the suites list
suites.extend(suite)
suites.extend(tsuite)
except TypeError:
yield suite, '{}.{}.{}'.format(
suite.__class__.__module__,
suite.__class__.__name__,
suite._testMethodName ).lower()
yield tsuite, '{}.{}.{}'.format(
tsuite.__class__.__module__,
tsuite.__class__.__name__,
tsuite._testMethodName ).lower()


class KayleeTestsLoader(unittest.TestLoader):
Expand All @@ -79,6 +85,7 @@ class KayleeTestsLoader(unittest.TestLoader):
"""

def __init__(self):
unittest.TestLoader.__init__(self)
self._default_suite = suite()

def loadTestsFromName(self, name, module = None):
Expand All @@ -97,14 +104,14 @@ def loadTestsFromName(self, name, module = None):
if not tests:
raise LookupError('Could not find test case for "{}"'.format(name))

suite = unittest.TestSuite()
tsuite = unittest.TestSuite()
if len(tests) == 1:
return tests[0]
for test in tests:
suite.addTest(test)
return suite
tsuite.addTest(test)
return tsuite


def main():
"""Runs the testsuite as command line application."""
"""runs the testsuite as command line application."""
unittest.main(testLoader = KayleeTestsLoader(), defaultTest = 'default')
63 changes: 30 additions & 33 deletions kaylee/testsuite/kaylee_tests.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# -*- coding: utf-8 -*-
import os
from kaylee.testsuite import KayleeTest, load_tests

import json

from kaylee.contrib import (MemoryTemporalStorage,
MemoryPermanentStorage,
MemoryNodesRegistry)

from projects.dummy_project.dummy import DummyProject, DummyController

import test_config
import json

from kaylee import NodeID, Node, Kaylee, KayleeError, loader
from kaylee.testsuite import KayleeTest, load_tests
from kaylee import NodeID, loader

# from datetime import datetime
from datetime import datetime

class KayleeTests(KayleeTest):
def setUp(self):
self.config = __import__('test_config')

def test_register_unregister(self):
kl = loader.load(test_config)
kl = loader.load(self.config)
node_json_config = kl.register('127.0.0.1')
node_config = json.loads(node_json_config)
self.assertEqual(len(node_config), 3)
Expand All @@ -33,25 +28,27 @@ def test_register_unregister(self):
kl.unregister(nid)
self.assertNotIn(nid, kl.registry)

# def test_subscribe_unsubscribe(self):
# kl = loader.load(test_config)
# app = kl.applications['dummy.1']
# node_json_config = kl.register('127.0.0.1')
# node_config = json.loads(node_json_config)
# node_id = node_config['node_id']

# # test node.subscribe
# app_json_config = kl.subscribe(node_id, 'dummy.1')
# app_config = json.loads(app_json_config)
# self.assertEqual(app_config['dummy_key'], 'dummy_value')
# node = kl.registry[node_id]
# self.assertEqual(node.controller, app)
# self.assertTrue(0 <= (datetime.now() - node.subscription_timestamp).seconds < 1)

# # test node.unsubscribe
# kl.unsubscribe(node_id)
# self.assertIsNone(node.controller)
# self.assertIsNone(node.subscription_timestamp)
# self.assertIn(node, kl.registry)
def test_subscribe_unsubscribe(self):
kl = loader.load(self.config)
app = kl.applications['dummy.1']
node_json_config = kl.register('127.0.0.1')
node_config = json.loads(node_json_config)
node_id = node_config['node_id']

# test node.subscribe
app_json_config = kl.subscribe(node_id, 'dummy.1')
app_config = json.loads(app_json_config)
self.assertEqual(app_config['dummy_key'], 'dummy_value')
node = kl.registry[node_id]
self.assertEqual(node.controller, app)
self.assertTrue(0 <= (datetime.now() -
node.subscription_timestamp).seconds < 1)

# test node.unsubscribe
kl.unsubscribe(node_id)
self.assertIsNone(node.controller)
self.assertIsNone(node.subscription_timestamp)
self.assertIn(node, kl.registry)


kaylee_suite = load_tests([KayleeTests])
8 changes: 5 additions & 3 deletions kaylee/testsuite/loader_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pylint: disable-msg=W0212
#pylint: disable-msg=W0212,W0611
#W0212: Access to a protected member
#W0611: Unused import PROJECTS_DIR # FALSE ALARM
#R0801: Similar lines in 2 files
###

from kaylee.testsuite import KayleeTest, load_tests, PROJECTS_DIR
Expand Down Expand Up @@ -69,7 +71,7 @@ def test_load_config_dict(self):
TestConfig.WORKER_SCRIPT_URL)

def test_load_config_module(self):
from . import test_config
test_config = __import__('test_config')
kl = loader.load(test_config)
self.assertIsInstance(kl, Kaylee)
self.assertEqual(kl._config.WORKER_SCRIPT_URL,
Expand All @@ -79,7 +81,7 @@ def test_load_config_path(self):
path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'test_config.py'))
kl = loader.load(path)
from . import test_config
test_config = __import__('test_config')
self.assertIsInstance(kl, Kaylee)
self.assertEqual(kl._config.WORKER_SCRIPT_URL,
test_config.WORKER_SCRIPT_URL)
Expand Down
11 changes: 8 additions & 3 deletions kaylee/testsuite/node_tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import unittest
from kaylee.testsuite import KayleeTest, load_tests
from datetime import datetime, timedelta
from kaylee import Node, NodeID
from kaylee import InvalidNodeIDError
from dummy_project import DummyController
from kaylee.testsuite.projects.dummy_project import DummyController


class NodeIDTests(KayleeTest):
Expand Down Expand Up @@ -46,6 +45,11 @@ def test_from_object(self):
self.assertRaises(InvalidNodeIDError, NodeID.from_object, node)

def test_internal_counter(self):
#pylint: disable-msg=W0612,W0212
#W0612: Unused variable 'i'
#W0212: Access to a protected member _inc of a client class

###
NodeID._inc = 0 # modified for test purposes only
remote = '127.0.0.1'
for i in xrange(0, 2**16 - 1):
Expand Down Expand Up @@ -128,7 +132,8 @@ def test_get_set_properties(self):
ctrl = DummyController.new_test_instance()
node.subscribe(ctrl)
now = datetime.now()
self.assertTrue(timedelta(seconds = 0) <= now - node.subscription_timestamp
self.assertTrue(timedelta(seconds = 0)
<= now - node.subscription_timestamp
<= timedelta(seconds = 3))
self.assertEqual(node.controller, ctrl)

Expand Down
6 changes: 3 additions & 3 deletions kaylee/testsuite/projects/dummy_project/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def __init__(self, *args, **kwargs):
self.x = 0
self.client_config = { 'dummy_key' : 'dummy_value' }

def normalize_result(self, data):
return data
def normalize_result(self, task_id, result):
return result

def next_task(self):
self.x += 1
Expand All @@ -29,7 +29,7 @@ def get_task(self, node):
return next(self.project)

def accept_result(self, node, data):
self.results.add(node.id, node.task_id, data)
pass

@staticmethod
def new_test_instance():
Expand Down
3 changes: 3 additions & 0 deletions kaylee/testsuite/projects/import_error_project/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#pylint: disable-msg=F0401
#F0401: Unable to import
###
import THIS_MODULE_DOES_NOT_EXIST_AND_IT_IS_FOR_IMPORT_ERROR_TEST
1 change: 1 addition & 0 deletions kaylee/testsuite/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pylint: disable-all
from kaylee.testsuite import PROJECTS_DIR


Expand Down
15 changes: 13 additions & 2 deletions kaylee/testsuite/util_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#pylint: disable-msg=W0402,W0212,E0202
#W0402: 15,0: Uses of a deprecated module 'string'
#W0212: Access to a protected member _wrapped of a client class
#E0202: KayleeUtilTests.test_lazy_object.NonLazy.x: An attribute
# affected in kaylee.testsuite.util_tests line 48 hide this method
# FALSE ALARM
###

import string
from kaylee.testsuite import KayleeTest, load_tests
from kaylee.util import (parse_timedelta, LazyObject, random_string,
Expand Down Expand Up @@ -31,6 +39,9 @@ def test_parse_timedelta(self):
self.assertRaises(KayleeError, parse_timedelta, '25x 10x')

def test_lazy_object(self):
#pylint: disable-msg=W0201
#W0201: lo.y defined outside __init__

class NonLazy(object):
def __init__(self):
self._x = 10
Expand Down Expand Up @@ -106,8 +117,8 @@ def test_get_secret_key(self):
self.assertRaises(KayleeError, get_secret_key)

# test loading from config
import test_config
from kaylee import kl, setup
from kaylee.testsuite import test_config
from kaylee import setup
setup(test_config)
sk = get_secret_key()
self.assertEqual(sk, test_config.SECRET_KEY)
Expand Down
2 changes: 1 addition & 1 deletion kaylee/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
:copyright: (c) 2012 by Zaur Nasibov.
:license: MIT, see LICENSE for more details.
"""

#pylint: disable-msg=W0402,W0212
#W0402: 15,0: Uses of a deprecated module 'string'
#W0212: Access to a protected member _wrapped of a client class
###

import re
import importlib
Expand Down

0 comments on commit 9e30694

Please sign in to comment.