Skip to content

Commit

Permalink
[WAYANG-#8] Add Integration test of Python-Platform
Browse files Browse the repository at this point in the history
Signed-off-by: bertty <[email protected]>
  • Loading branch information
Bertty Contreras-Rojas authored and berttty committed Apr 8, 2022
1 parent c355af5 commit 9cc3db2
Show file tree
Hide file tree
Showing 4 changed files with 16,931 additions and 30 deletions.
35 changes: 19 additions & 16 deletions python/src/pywy/graph/graph.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from pywy.types import T
from typing import (Iterable, Dict, Callable, Any, Generic, Optional)
from pywy.types import T, K
from typing import (Iterable, Dict, Callable, Any, Generic, Optional, List)


class GraphNode(Generic[T]):
class GraphNode(Generic[K, T]):
current: T
visited: bool

def __init__(self, op: T):
self.current = op
self.visited = False

def get_adjacents(self) -> Iterable[T]:
def get_adjacents(self) -> List[K]:
pass

def build_node(self, t: T) -> 'GraphNode[T]':
def build_node(self, t: T) -> 'GraphNode[K, T]':
pass

def walk(self, created: Dict[T, 'GraphNode[T]']) -> Iterable['GraphNode[T]']:
def walk(self, created: Dict[K, 'GraphNode[K, T]']) -> Iterable['GraphNode[K, T]']:
adjacent = self.get_adjacents()

def wrap(op: T):
if len(adjacent) == 0:
return []

def wrap(op: T) -> 'GraphNode[K, T]':
if op is None:
return None
if op not in created:
Expand All @@ -29,18 +32,18 @@ def wrap(op: T):
return map(wrap, adjacent)

def visit(self,
parent: 'GraphNode[T]',
udf: Callable[['GraphNode[T]', 'GraphNode[T]'], Any],
parent: 'GraphNode[K, T]',
udf: Callable[['GraphNode[K, T]', 'GraphNode[K, T]'], Any],
visit_status: bool = True):
if self.visited == visit_status:
return
self.visited = ~ visit_status
return udf(self, parent)


class WayangGraph(Generic[T]):
starting_nodes: Iterable[GraphNode[T]]
created_nodes: Dict[T, GraphNode[T]]
class WayangGraph(Generic[K, T]):
starting_nodes: Iterable[GraphNode[K, T]]
created_nodes: Dict[K, GraphNode[K, T]]

def __init__(self, nodes: Iterable[T]):
self.created_nodes = {}
Expand All @@ -51,14 +54,14 @@ def __init__(self, nodes: Iterable[T]):
self.created_nodes[node] = tmp
self.starting_nodes = start

def build_node(self, t: T) -> GraphNode[T]:
def build_node(self, t: T) -> GraphNode[K, T]:
pass

def traversal(
self,
origin: GraphNode[T],
nodes: Iterable[GraphNode[T]],
udf: Callable[[GraphNode[T], GraphNode[T]], Any],
origin: GraphNode[K, T],
nodes: Iterable[GraphNode[K, T]],
udf: Callable[[GraphNode[K, T], GraphNode[K, T]], Any],
visit_status: bool = True
):
for node in nodes:
Expand Down
14 changes: 7 additions & 7 deletions python/src/pywy/graph/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from pywy.operators.base import PywyOperator


class NodeOperator(GraphNode[PywyOperator]):
class NodeOperator(GraphNode[PywyOperator, PywyOperator]):

def __init__(self, op: PywyOperator):
super(NodeOperator, self).__init__(op)

def get_adjacents(self) -> Iterable[PywyOperator]:
def get_adjacents(self) -> List[PywyOperator]:
operator: PywyOperator = self.current
if operator is None or operator.inputs == 0:
return []
Expand All @@ -19,7 +19,7 @@ def build_node(self, t: PywyOperator) -> 'NodeOperator':
return NodeOperator(t)


class WGraphOfOperator(WayangGraph[NodeOperator]):
class WGraphOfOperator(WayangGraph[PywyOperator, NodeOperator]):

def __init__(self, nodes: Iterable[PywyOperator]):
super(WGraphOfOperator, self).__init__(nodes)
Expand All @@ -28,16 +28,16 @@ def build_node(self, t: PywyOperator) -> NodeOperator:
return NodeOperator(t)


class NodeVec(GraphNode[List[PywyOperator]]):
class NodeVec(GraphNode[PywyOperator, List[PywyOperator]]):

def __init__(self, op: PywyOperator):
super(NodeVec, self).__init__([op, None])

def get_adjacents(self) -> Iterable[List[PywyOperator]]:
def get_adjacents(self) -> List[PywyOperator]:
operator: PywyOperator = self.current[0]
if operator is None or operator.inputs == 0:
return []
return [operator.inputOperator, None]
return operator.inputOperator

def build_node(self, t: PywyOperator) -> 'NodeVec':
return NodeVec(t)
Expand All @@ -49,7 +49,7 @@ def __repr__(self):
return self.__str__()


class WGraphOfVec(WayangGraph[NodeVec]):
class WGraphOfVec(WayangGraph[PywyOperator, NodeVec]):

def __init__(self, nodes: Iterable[PywyOperator]):
super(WGraphOfVec, self).__init__(nodes)
Expand Down
40 changes: 33 additions & 7 deletions python/src/pywy/tests/integration/python_platform_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
import unittest
import tempfile
from os import fdopen
from typing import List

from pywy.config import RC_TEST_DIR as ROOT
from pywy.dataquanta import WayangContext
from pywy.plugins import PYTHON


class TestIntegrationPythonPlatform(unittest.TestCase):

file_10e0: str

def setUp(self):
self.file_10e0 = "{}/10e0MB.input".format(ROOT)
pass

def test_TO_REMOVE(self):
"""
TODO REMOVE THIS TEST, IT JUST TO VALIDATE THAT EVERYTHING IS CORRECT IN TERMS OF ENVIRONMENT
Returns
-------
def test_grep(self):
def pre(a: str) -> bool:
return 'six' in a

fd, path_tmp = tempfile.mkstemp()

WayangContext() \
.register(PYTHON) \
.textfile(self.file_10e0) \
.filter(pre) \
.store_textfile(path_tmp)

lines_filter: List[str]
with open(self.file_10e0, 'r') as f:
lines_filter = list(filter(pre, f.readlines()))
selectivity = len(list(lines_filter))

"""
self.assertEqual("a", "a")
lines_platform: List[str]
with fdopen(path_tmp, 'r') as fp:
lines_platform = fp.readlines()
elements = len(lines_platform)

self.assertEqual(selectivity, elements)
self.assertEqual(lines_filter, lines_platform)
Loading

0 comments on commit 9cc3db2

Please sign in to comment.