Skip to content

Commit

Permalink
[modify] for python2.5 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
bellbind committed Aug 6, 2010
1 parent 1dac33d commit 465938e
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/first.py 100644 → 100755
Expand Up @@ -3,6 +3,7 @@
# generate md doc: python -m specfor.doc examples.first

# import
from __future__ import with_statement
from specfor import the, spec


Expand Down
7 changes: 4 additions & 3 deletions specfor/__init__.py 100644 → 100755
@@ -1,7 +1,8 @@
version = "0.0.6"
from .framework import *
from .expectation import *
from .mockings import *

from .framework import spec
from .expectation import the
from .mockings import mock

def new_specfor():
import sys
Expand Down
11 changes: 6 additions & 5 deletions specfor/match.py 100644 → 100755
Expand Up @@ -118,11 +118,12 @@ def __call__(self, expected):
eindex = 0
lefts = []
not_founds = []
for match in matches:
lefts.extend(value[vindex:match.a])
not_founds.extend(exp[eindex:match.b])
vindex = match.a + match.size
eindex = match.b + match.size

for a, b, size in matches:
lefts.extend(value[vindex:a])
not_founds.extend(exp[eindex:b])
vindex = a + size
eindex = b + size
pass

assert not lefts and not not_founds, "".join(
Expand Down
6 changes: 3 additions & 3 deletions specfor/mockings/restrictions/args.py 100644 → 100755
Expand Up @@ -113,21 +113,21 @@ def __repr__(self):

def just_factory(resp, kwargs):
kwspecs = dict((k, ArgSpecJust(k, v)) for k, v in kwargs.items())
funcspec = inspect.getargspec(resp.result)
funcspec = util.getargspec(resp.result)
argspec = ArgSpecs(kwspecs, funcspec)
return ArgsRestiction(argspec)
plugins.register("just", just_factory)

def like_factory(resp, kwargs):
kwspecs = dict((k, ArgSpecLike(k, v)) for k, v in kwargs.items())
funcspec = inspect.getargspec(resp.result)
funcspec = util.getargspec(resp.result)
argspec = ArgSpecs(kwspecs, funcspec)
return ArgsRestiction(argspec)
plugins.register("like", like_factory)

def unless_factory(resp, kwargs):
kwspecs = dict((k, ArgSpecNot(k, v)) for k, v in kwargs.items())
funcspec = inspect.getargspec(resp.result)
funcspec = util.getargspec(resp.result)
argspec = ArgSpecs(kwspecs, funcspec)
return ArgsRestiction(argspec)
plugins.register("unless", unless_factory)
Expand Down
22 changes: 22 additions & 0 deletions specfor/mockings/util.py 100644 → 100755
@@ -1,4 +1,26 @@

class funcspec(object):
def __init__(self, argspec):
self.argspec = argspec
pass
@property
def args(self):
return self.argspec[0]
@property
def varargs(self):
return self.argspec[1]
@property
def keywords(self):
return self.argspec[2]
@property
def defaults(self):
return self.argspec[3]
pass

def getargspec(func):
import inspect
return funcspec(inspect.getargspec(func))

def bindargs(funcspec, args, kwargs):
"""bind arg name and value by funcspec:
Expand Down
1 change: 1 addition & 0 deletions specs/for_expectation.py 100644 → 100755
@@ -1,3 +1,4 @@
from __future__ import with_statement
from specfor import spec


Expand Down
1 change: 1 addition & 0 deletions specs/for_mock.py 100644 → 100755
@@ -1,3 +1,4 @@
from __future__ import with_statement
from specfor import the, spec

mock_spec = spec.of("mock")
Expand Down
1 change: 1 addition & 0 deletions specs/for_mock_ordered.py 100644 → 100755
@@ -1,3 +1,4 @@
from __future__ import with_statement
from specfor import the, spec

ordered_mock_spec = spec.of("mock with ordered call")
Expand Down
1 change: 1 addition & 0 deletions specs/for_mock_plugin.py 100644 → 100755
@@ -1,3 +1,4 @@
from __future__ import with_statement
from specfor import spec, the

spec_mock_plugin = spec.of("mock plugin")
Expand Down

0 comments on commit 465938e

Please sign in to comment.