Commit cd97e364 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez
Browse files

added tests

parent 6eadbe43
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -557,7 +557,7 @@ class Edge(dict, MutableMapping):
        """
        self.overlap_latlon_coords, self["source_mbr"], self["destin_mbr"] = self.source.geodata.compute_overlap(self.destination.geodata, **kwargs)

    def get_matches(self):
    def get_matches(self): # pragma: no cover
        if self.matches.empty:
            return pd.DataFrame()

+15 −0
Original line number Diff line number Diff line
@@ -247,3 +247,18 @@ def test_is_complete(graph):

    assert False == incomplete_graph.is_complete()
    assert True == graph.is_complete()

def test_apply(graph):
    def set_matches(x):
        s,d,e = x
        e.matches = ['fake', 'fake', 'fake']

    def get_matches(x):
        s,d,e = x
        return e.matches

    graph.apply(set_matches)
    results = graph.apply(get_matches)

    for matches in results:
        assert len(matches) == 3
+32 −0
Original line number Diff line number Diff line
@@ -159,3 +159,35 @@ class TestUtils(unittest.TestCase):
        patchwork = Patchwork(a=1, b=2, c=3)
        self.assertEqual(patchwork.get(['a', 'b']), [1, 2])
        self.assertEqual(patchwork.get('c'), 3)

    def test_decorate_class(self):
        class Test(object):
            def __init__(self):
                self.test = 'original'

            def get_test(self):
                return self.test

        def dec(func):
            return lambda x:'decorated'

        Dec_Test = utils.decorate_class(Test, dec)

        undecorated = Test()
        decorated = Dec_Test()

        self.assertEqual(undecorated.get_test(), 'original')
        self.assertEqual(decorated.get_test(), 'decorated')

    def test_decorate_class(self):
        def func_to_wrap(x):
            return x+1

        def wrapper():
            # Should be able to access run-time namespace
            return ret + 1, test

        decorator = utils.create_decorator(wrapper, test=0)
        wrapped_func = decorator(func_to_wrap)

        self.assertTrue(wrapped_func(1),2)
+10 −4
Original line number Diff line number Diff line
@@ -387,6 +387,9 @@ def decorate_class(cls, decorator, exclude=[], *args, **kwargs):
    args, kwargs : list, dict
                   Parameters to pass into decorator
    """
    if not callable(decorator):
        raise Exception('Decorator must be callable.')

    def decorate(cls):
        attributes = cls.__dict__.keys()
        for attr in attributes: # there's propably a better way to do this
@@ -405,10 +408,13 @@ def create_decorator(dec, **namespace):
    can be used in the body. Originally designed with the idea of automatically
    updating one object after the decorated object was modified.
    """
    def decorator(func):
        def wrapper(self, *args, **kwargs):
            ret = func(self, *args, **kwargs)
            exec(dec, *args, **kwargs)

    def decorator(func, *args, **kwargs):
        def wrapper(*args, **kwarg):
            for key in namespace.keys():
                locals()[key] = namespace[key]
            ret = func(*args, **kwargs)
            exec(dec.__code__, locals(), globals())
            if ret:
                return ret
        return wrapper