Skip to content
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
10 changes: 5 additions & 5 deletions checkpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ def testModule(moduleName):
"""
Test all files from module
"""
import caches
from . import caches
caches.clearAllCaches()
import tester
from . import tester
results = tester.testModule(moduleName)
try:
if __IPYTHON__:
Expand All @@ -18,9 +18,9 @@ def test(fileName):
"""
Run tests for a single file
"""
import caches
from . import caches
caches.clearAllCaches()
import tester
from . import tester
result = tester.test(fileName)
try:
if __IPYTHON__:
Expand All @@ -30,4 +30,4 @@ def test(fileName):
pass
return result

from downloader import download, update
from .downloader import download, update
4 changes: 2 additions & 2 deletions checkpy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import os
import argparse
import downloader
import tester
from . import downloader
from . import tester
import shutil
import time

Expand Down
4 changes: 2 additions & 2 deletions checkpy/assertlib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lib
from . import lib
import re
import os

Expand All @@ -18,7 +18,7 @@ def contains(actual, expectedElement):
return expectedElement in actual

def containsOnly(actual, expectedElements):
return len(filter(lambda e : e not in expectedElements, actual)) == 0
return len([e for e in actual if e not in expectedElements]) == 0

def sameType(actual, expected):
return type(actual) is type(expected)
Expand Down
13 changes: 7 additions & 6 deletions checkpy/downloader.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import requests
import zipfile as zf
import StringIO
import io
import os
import shutil
import tinydb
import caches
import printer
from . import caches
from . import printer
from functools import reduce

class Folder(object):
def __init__(self, name, path):
Expand Down Expand Up @@ -60,7 +61,7 @@ def pathFromFolder(self, folderName):
return Path(path)

def __add__(self, other):
if isinstance(other, str) or isinstance(other, unicode):
if isinstance(other, str) or isinstance(other, str):
return Path(os.path.join(self.asString(), other))
return Path(os.path.join(self.asString(), other.asString()))

Expand All @@ -85,7 +86,7 @@ def __eq__(self, other):
def __contains__(self, item):
return item in [item for item in self]

def __nonzero__ (self):
def __bool__ (self):
return len(self.asString()) != 0


Expand Down Expand Up @@ -133,7 +134,7 @@ def _download(githubUserName, githubRepoName):

_addToDownloadLocations(githubUserName, githubRepoName)

with zf.ZipFile(StringIO.StringIO(r.content)) as z:
with zf.ZipFile(io.StringIO(r.content)) as z:
destFolder = Folder(githubRepoName, TESTSFOLDER.path + githubRepoName)

existingTests = set()
Expand Down
22 changes: 12 additions & 10 deletions checkpy/lib.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import sys
import re
import StringIO
import io
import contextlib
import importlib
import imp
import cStringIO
import io
import tokenize
import exception as excep
import caches
from . import exception as excep
from . import caches
import collections
from functools import reduce

@contextlib.contextmanager
def _stdoutIO(stdout=None):
old = sys.stdout
if stdout is None:
stdout = StringIO.StringIO()
stdout = io.StringIO()
sys.stdout = stdout
yield stdout
sys.stdout = old
Expand All @@ -27,7 +29,7 @@ def new_input(prompt = None):

old = sys.stdin
if stdin is None:
stdin = StringIO.StringIO()
stdin = io.StringIO()
sys.stdin = stdin

yield stdin
Expand Down Expand Up @@ -94,13 +96,13 @@ def moduleAndOutputFromSource(fileName, source, stdinArgs = None):
moduleName = fileName[:-3] if fileName.endswith(".py") else fileName
try:
mod = imp.new_module(moduleName)
exec source in mod.__dict__
exec(source, mod.__dict__)
sys.modules[moduleName] = mod

except Exception as e:
exception = excep.SourceException(e, "while trying to import the code")

for name, func in [(name, f) for name, f in mod.__dict__.iteritems() if callable(f)]:
for name, func in [(name, f) for name, f in mod.__dict__.items() if isinstance(f, collections.Callable)]:
if func.__module__ == moduleName:
setattr(mod, name, wrapFunctionWithExceptionHandler(func))
output = stdout.getvalue()
Expand Down Expand Up @@ -129,7 +131,7 @@ def exceptionWrapper(*args, **kwargs):
return func(*args, **kwargs)
except Exception as e:
argListRepr = reduce(lambda xs, x : xs + ", " + x, ["{}={}".format(func.__code__.co_varnames[i], args[i]) for i in range(len(args))]) if args else ""
for kwargName in func.__code__.co_varnames[len(args):func.func_code.co_argcount]:
for kwargName in func.__code__.co_varnames[len(args):func.__code__.co_argcount]:
argListRepr += ", {}={}".format(kwargName, kwargs[kwargName])

if not argListRepr:
Expand All @@ -155,7 +157,7 @@ def getLine(text, lineNumber):

# inspiration from http://stackoverflow.com/questions/1769332/script-to-remove-python-comments-docstrings
def removeComments(source):
io_obj = cStringIO.StringIO(source)
io_obj = io.StringIO(source)
out = ""
prev_toktype = tokenize.INDENT
last_lineno = -1
Expand Down
16 changes: 8 additions & 8 deletions checkpy/printer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import exception as excep
from . import exception as excep
import os
import colorama
colorama.init()
Expand All @@ -20,36 +20,36 @@ def display(testResult):
msg = "{}{} {}{}".format(color, smiley, testResult.description, _Colors.ENDC)
if testResult.message:
msg += "\n - {}".format(testResult.message)
print msg
print(msg)
return msg

def displayTestName(testName):
msg = "{}Testing: {}{}".format(_Colors.NAME, testName, _Colors.ENDC)
print msg
print(msg)
return msg

def displayUpdate(fileName):
msg = "{}Updated: {}{}".format(_Colors.WARNING, os.path.basename(fileName), _Colors.ENDC)
print msg
print(msg)
return msg

def displayRemoved(fileName):
msg = "{}Removed: {}{}".format(_Colors.WARNING, os.path.basename(fileName), _Colors.ENDC)
print msg
print(msg)
return msg

def displayAdded(fileName):
msg = "{}Added: {}{}".format(_Colors.WARNING, os.path.basename(fileName), _Colors.ENDC)
print msg
print(msg)
return msg

def displayCustom(message):
print message
print(message)
return message

def displayError(message):
msg = "{}{} {}{}".format(_Colors.WARNING, _Smileys.CONFUSED, message, _Colors.ENDC)
print msg
print(msg)
return msg

def _selectColorAndSmiley(testResult):
Expand Down
7 changes: 4 additions & 3 deletions checkpy/tester.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import printer
import caches
from . import printer
from . import caches
import os
import sys
import importlib
import re
import multiprocessing
import time
import dill
import collections

HERE = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -138,7 +139,7 @@ def run(self):
return

reservedNames = ["before", "after"]
testCreators = [method for method in self.module.__dict__.values() if callable(method) and method.__name__ not in reservedNames]
testCreators = [method for method in list(self.module.__dict__.values()) if isinstance(method, collections.Callable) and method.__name__ not in reservedNames]

result.nTests = len(testCreators)

Expand Down
2 changes: 1 addition & 1 deletion checkpy/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import caches
from . import caches

class Test(object):
def __init__(self, priority):
Expand Down