Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Python 2.6 compatibility. #2

Open
wants to merge 2 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: 3 additions & 3 deletions pinject/annotations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"""


import unittest
import unittest2

from pinject import annotations


class AnnotationTest(unittest.TestCase):
class AnnotationTest(unittest2.TestCase):

def test_as_correct_adjective(self):
self.assertEqual('annotated with "foo"',
Expand All @@ -40,7 +40,7 @@ def test_not_equal(self):
hash(annotations.Annotation('bar')))


class NoAnnotationTest(unittest.TestCase):
class NoAnnotationTest(unittest2.TestCase):

def test_as_correct_adjective(self):
self.assertEqual('unannotated',
Expand Down
4 changes: 2 additions & 2 deletions pinject/arg_binding_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def create_kwargs(arg_binding_keys, provider_fn):
Returns:
a (possibly empty) map from arg name to provided value
"""
return {arg_binding_key._arg_name: provider_fn(arg_binding_key)
for arg_binding_key in arg_binding_keys}
return dict([(arg_binding_key._arg_name, provider_fn(arg_binding_key))
for arg_binding_key in arg_binding_keys])


_PROVIDE_PREFIX = 'provide_'
Expand Down
10 changes: 5 additions & 5 deletions pinject/arg_binding_keys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"""


import unittest
import unittest2

from pinject import annotations
from pinject import arg_binding_keys
from pinject import binding_keys
from pinject import provider_indirections


class ArgBindingKeyTest(unittest.TestCase):
class ArgBindingKeyTest(unittest2.TestCase):

def test_repr(self):
arg_binding_key = arg_binding_keys.ArgBindingKey(
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_doesnt_conflict_with_any_binding_key(self):
[non_conflicting_arg_binding_key]))


class GetUnboundArgNamesTest(unittest.TestCase):
class GetUnboundArgNamesTest(unittest2.TestCase):

def test_all_arg_names_bound(self):
self.assertEqual(
Expand All @@ -137,7 +137,7 @@ def test_some_arg_name_unbound(self):
['bound', 'unbound'], [arg_binding_keys.new('bound')]))


class CreateKwargsTest(unittest.TestCase):
class CreateKwargsTest(unittest2.TestCase):

def test_returns_nothing_for_no_input(self):
self.assertEqual(
Expand All @@ -154,7 +154,7 @@ def ProviderFn(arg_binding_key):
ProviderFn))


class NewArgBindingKeyTest(unittest.TestCase):
class NewArgBindingKeyTest(unittest2.TestCase):

def test_with_no_bells_or_whistles(self):
arg_binding_key = arg_binding_keys.new('an-arg-name')
Expand Down
6 changes: 3 additions & 3 deletions pinject/binding_keys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"""


import unittest
import unittest2

from pinject import annotations
from pinject import binding_keys


class BindingKeyTest(unittest.TestCase):
class BindingKeyTest(unittest2.TestCase):

def test_repr(self):
binding_key = binding_keys.BindingKey(
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_unequal_if_not_same_annotation(self):
self.assertNotEqual(str(binding_key_one), str(binding_key_two))


class NewBindingKeyTest(unittest.TestCase):
class NewBindingKeyTest(unittest2.TestCase):

def test_without_annotation(self):
binding_key = binding_keys.new('an-arg-name')
Expand Down
22 changes: 11 additions & 11 deletions pinject/bindings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


import threading
import unittest
import unittest2

from pinject import bindings as bindings_lib
from pinject import binding_keys
Expand All @@ -41,7 +41,7 @@ def new_in_default_scope(binding_key):
get_binding_loc_fn=lambda: 'unknown')


class GetBindingKeyToBindingMapsTest(unittest.TestCase):
class GetBindingKeyToBindingMapsTest(unittest2.TestCase):

def setUp(self):
class SomeClass(object):
Expand Down Expand Up @@ -97,7 +97,7 @@ def handle_binding_collision_fn(
self.assertTrue(was_called.is_set())


class GetOverallBindingKeyToBindingMapsTest(unittest.TestCase):
class GetOverallBindingKeyToBindingMapsTest(unittest2.TestCase):

def setUp(self):
class SomeClass(object):
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_colliding_highest_priority_bindings_raises_error(self):
error_type=errors.ConflictingExplicitBindingsError)


class BindingMappingTest(unittest.TestCase):
class BindingMappingTest(unittest2.TestCase):

def test_success(self):
binding_mapping = bindings_lib.BindingMapping(
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_verifying_missing_required_binding_raises_error(self):
'unknown-binding-key', 'a-require-loc')])


class DefaultGetArgNamesFromClassNameTest(unittest.TestCase):
class DefaultGetArgNamesFromClassNameTest(unittest2.TestCase):

def test_single_word_lowercased(self):
self.assertEqual(
Expand Down Expand Up @@ -237,7 +237,7 @@ def call_provisor_fn(a_binding):
_UNUSED_INJECTION_CONTEXT, FakeObjectProvider(), pargs=[], kwargs={})


class GetExplicitClassBindingsTest(unittest.TestCase):
class GetExplicitClassBindingsTest(unittest2.TestCase):

def test_returns_no_bindings_for_no_input(self):
self.assertEqual([], bindings_lib.get_explicit_class_bindings([]))
Expand Down Expand Up @@ -265,7 +265,7 @@ def __init__(self):
explicit_binding.binding_key)


class GetProviderBindingsTest(unittest.TestCase):
class GetProviderBindingsTest(unittest2.TestCase):

def test_returns_no_bindings_for_non_binding_spec(self):
class SomeClass(object):
Expand Down Expand Up @@ -304,7 +304,7 @@ def provide_foo(self):
SomeBindingSpec(), known_scope_ids=[])


class GetImplicitClassBindingsTest(unittest.TestCase):
class GetImplicitClassBindingsTest(unittest2.TestCase):

def test_returns_no_bindings_for_no_input(self):
self.assertEqual([], bindings_lib.get_implicit_class_bindings([]))
Expand Down Expand Up @@ -346,7 +346,7 @@ class SomeClass(object):
implicit_binding.binding_key)


class BinderTest(unittest.TestCase):
class BinderTest(unittest2.TestCase):

def setUp(self):
self.collected_bindings = []
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_binding_to_non_class_raises_error(self):
to_class='not-a-class')


class BindingSpecTest(unittest.TestCase):
class BindingSpecTest(unittest2.TestCase):

def test_equal_if_same_type(self):
class SomeBindingSpec(bindings_lib.BindingSpec):
Expand All @@ -435,7 +435,7 @@ class BindingSpecTwo(bindings_lib.BindingSpec):
self.assertNotEqual(hash(BindingSpecOne()), hash(BindingSpecTwo()))


class GetProviderFnBindingsTest(unittest.TestCase):
class GetProviderFnBindingsTest(unittest2.TestCase):

def test_proviser_calls_provider_fn(self):
def provide_foo():
Expand Down
18 changes: 9 additions & 9 deletions pinject/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


import inspect
import unittest
import unittest2

from pinject import arg_binding_keys
from pinject import bindings
Expand All @@ -40,7 +40,7 @@ def call_with_injection(self, provider_fn, injection_context):
return provider_fn()


class AnnotateArgTest(unittest.TestCase):
class AnnotateArgTest(unittest2.TestCase):

def test_adds_binding_in_pinject_decorated_fn(self):
@decorators.annotate_arg('foo', 'an-annotation')
Expand All @@ -51,7 +51,7 @@ def some_function(foo):
some_function, decorators._ARG_BINDING_KEYS_ATTR)])


class InjectTest(unittest.TestCase):
class InjectTest(unittest2.TestCase):

def test_can_set_injectable_arg_names(self):
@decorators.inject(['foo', 'bar'])
Expand Down Expand Up @@ -143,7 +143,7 @@ def some_function(foo, bar):
self.assertRaises(errors.DuplicateDecoratorError, do_bad_inject)


class InjectableTest(unittest.TestCase):
class InjectableTest(unittest2.TestCase):

def test_adds_wrapper_to_init(self):
class SomeClass(object):
Expand All @@ -154,7 +154,7 @@ def __init__(self, foo):
hasattr(SomeClass.__init__, decorators._IS_WRAPPER_ATTR))


class ProvidesTest(unittest.TestCase):
class ProvidesTest(unittest2.TestCase):

def test_sets_arg_values(self):
@decorators.provides('an-arg-name', annotated_with='an-annotation',
Expand Down Expand Up @@ -206,7 +206,7 @@ def provide_something(self):
for provider_fn_binding in provider_fn_bindings]))


class GetProviderFnDecorationsTest(unittest.TestCase):
class GetProviderFnDecorationsTest(unittest2.TestCase):

def test_returns_defaults_for_undecorated_fn(self):
def provide_foo():
Expand Down Expand Up @@ -242,7 +242,7 @@ def provide_foo():
provider_decorations)


class GetPinjectWrapperTest(unittest.TestCase):
class GetPinjectWrapperTest(unittest2.TestCase):

def test_sets_recognizable_wrapper_attribute(self):
@decorators.annotate_arg('foo', 'an-annotation')
Expand Down Expand Up @@ -296,7 +296,7 @@ def some_function(foo, bar='BAR', *pargs, **kwargs):
self.assertEqual(('BAR',), defaults)


class IsExplicitlyInjectableTest(unittest.TestCase):
class IsExplicitlyInjectableTest(unittest2.TestCase):

def test_non_injectable_class(self):
class SomeClass(object):
Expand All @@ -311,7 +311,7 @@ def __init__(self):
self.assertTrue(decorators.is_explicitly_injectable(SomeClass))


class GetInjectableArgBindingKeysTest(unittest.TestCase):
class GetInjectableArgBindingKeysTest(unittest2.TestCase):

def assert_fn_has_injectable_arg_binding_keys(self, fn, arg_binding_keys):
self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions pinject/finding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@


import sys
import unittest
import unittest2

from pinject import finding


class FindClassesTest(unittest.TestCase):
class FindClassesTest(unittest2.TestCase):

def test_finds_passed_in_classes(self):
class SomeClass(object):
Expand Down
6 changes: 3 additions & 3 deletions pinject/initializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@


import inspect
import unittest
import unittest2

from pinject import errors
from pinject import initializers


class CopyArgsToInternalFieldsTest(unittest.TestCase):
class CopyArgsToInternalFieldsTest(unittest2.TestCase):

def test_does_nothing_extra_for_zero_arg_initializer(self):
class SomeClass(object):
Expand Down Expand Up @@ -86,7 +86,7 @@ def some_function(foo, bar):
do_bad_decorated_fn)


class CopyArgsToPublicFieldsTest(unittest.TestCase):
class CopyArgsToPublicFieldsTest(unittest2.TestCase):

def test_uses_no_field_prefix(self):
class SomeClass(object):
Expand Down
4 changes: 2 additions & 2 deletions pinject/injection_contexts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""


import unittest
import unittest2

from pinject import binding_keys
from pinject import bindings
Expand All @@ -25,7 +25,7 @@
_UNUSED_INJECTION_SITE_FN = lambda: None


class InjectionContextTest(unittest.TestCase):
class InjectionContextTest(unittest2.TestCase):

def setUp(self):
self.binding_key = binding_keys.new('foo')
Expand Down
14 changes: 7 additions & 7 deletions pinject/locations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"""


import unittest
import unittest2

from pinject import locations


class GetTypeLocTest(unittest.TestCase):
class GetTypeLocTest(unittest2.TestCase):

def test_known(self):
class SomeObject(object):
Expand All @@ -28,10 +28,10 @@ class SomeObject(object):

def test_unknown(self):
self.assertEqual('unknown location',
locations.get_loc(unittest.TestCase))
locations.get_loc(unittest2.TestCase))


class GetClassNameAndLocTest(unittest.TestCase):
class GetClassNameAndLocTest(unittest2.TestCase):

def test_known(self):
class OtherObject(object):
Expand All @@ -49,11 +49,11 @@ def a_method(self):
self.assertIn('locations_test.py', class_name_and_loc)

def test_unknown(self):
self.assertEqual('unittest.case.TestCase',
locations.get_name_and_loc(unittest.TestCase))
self.assertEqual('unittest2.case.TestCase',
locations.get_name_and_loc(unittest2.TestCase))


class GetBackFrameLocTest(unittest.TestCase):
class GetBackFrameLocTest(unittest2.TestCase):

def test_correct_file_and_line(self):
def get_loc():
Expand Down
3 changes: 2 additions & 1 deletion pinject/object_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def _verify_callable(fn, arg_name):

def _pare_to_present_args(kwargs, fn):
arg_names, _, _, _ = inspect.getargspec(fn)
return {arg: value for arg, value in kwargs.iteritems() if arg in arg_names}
return dict([
(arg, value) for arg, value in kwargs.iteritems() if arg in arg_names])


class ObjectGraph(object):
Expand Down
Loading