Skip to content

Commit

Permalink
added abstract class to select appropriate Cython classes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Aug 7, 2018
1 parent 1b02bdc commit dee3c65
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
19 changes: 19 additions & 0 deletions graphi/types/cython_graph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ...abc import Graph as GraphABC
from ..decorator import boundable, undirectable

from .plain_graph import CythonGraph as _PlainGraph


@boundable
@undirectable
class CythonGraph(GraphABC):
"""
Optimised Cython Graph Implementations
.. note:: This is an abstract class that merely picks the most suitable implementation.
"""
def __new__(cls, *args, **kwargs):
return _PlainGraph(*args, **kwargs)


CythonGraph.register(_PlainGraph)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def __new__(cls, *args, **kwargs):


@unittest.skipIf(platform.python_implementation() != 'CPython', 'Cython extension not available outside of CPython')
class TestCythonGraphInterface(mixins.Mixin.GraphInitMixin, mixins.Mixin.GraphInterfaceMixin):
class TestCythonPlainGraphInterface(mixins.Mixin.GraphInitMixin, mixins.Mixin.GraphInterfaceMixin):
graph_cls = CythonGraph
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import platform
try:
import unittest2 as unittest
except ImportError:
import unittest

try:
from graphi.types.cython_graph import CythonGraph
except ImportError as err:
class CythonGraph(object):
failure_reason = str(err)

def __new__(cls, *args, **kwargs):
raise ImportError(cls.failure_reason)
del err

from graphi_unittests.types_unittests import _graph_interface_mixins as mixins


@unittest.skipIf(platform.python_implementation() != 'CPython', 'Cython extension not available outside of CPython')
class TestCythonGraphInterface(mixins.Mixin.GraphInitMixin, mixins.Mixin.GraphInterfaceMixin):
graph_cls = CythonGraph

0 comments on commit dee3c65

Please sign in to comment.