tobe

Finished
1NODE, EDGE, ATTR = range(3)
21
2import sys, pytest, collections, collections.abc, urllib3.exceptions, _pytest.pytester, numpy;
3collections.Mapping = collections.abc.Mapping;
4collections.MutableMapping = collections.abc.MutableMapping;
5collections.MutableSet = collections.abc.MutableSet;
6collections.Sequence = collections.abc.Sequence;
7collections.Callable = collections.abc.Callable;
8collections.Iterable = collections.abc.Iterable;
9collections.Iterator = collections.abc.Iterator;
10urllib3.exceptions.SNIMissingWarning = urllib3.exceptions.DependencyWarning;
11pytest.RemovedInPytest4Warning = DeprecationWarning;
12_pytest.pytester.Testdir = _pytest.pytester.Pytester;
13numpy.PINF = numpy.inf;
14numpy.unicode_ = numpy.str_;
15numpy.bytes_ = numpy.bytes_;
16numpy.float_ = numpy.float64;
17numpy.string_ = numpy.bytes_;
18numpy.NaN = numpy.nan;
19
20
21NODE, EDGE, ATTR = range(3)
322
423class Node:
5 def __init__(self, name: str, attrs: dict):
24 def __init__(self, name, attrs=None):
625 self.name = name
7 self.attrs = attrs
8
26 self.attrs = attrs or {}
27
928 def __eq__(self, other):
1029 return self.name == other.name and self.attrs == other.attrs
11
30
31 def __repr__(self):
32 return f"Node({self.name!r}, {self.attrs!r})"
1233
1334class Edge:
14 def __init__(self, src: str, dst: str, attrs: dict):
35 def __init__(self, src, dst, attrs=None):
1536 self.src = src
1637 self.dst = dst
17 self.attrs = attrs
18
38 self.attrs = attrs or {}
39
1940 def __eq__(self, other):
20 return (self.src == other.src and
21 self.dst == other.dst and
22 self.attrs == other.attrs)
23
41 return self.src == other.src and self.dst == other.dst and self.attrs == other.attrs
42
43 def __repr__(self):
44 return f"Edge({self.src!r}, {self.dst!r}, {self.attrs!r})"
2445
2546class Graph:
26 def __init__(self, data: list | None = None):
27 pass
47 def __init__(self, data=None):
48 # Initialize empty collections
49 self.nodes = []
50 self.edges = []
51 self.attrs = {}
52
53 # Check if data is None or not a list
54 if data is None or not isinstance(data, list):
55 raise TypeError("Graph data malformed")
56
57 # Process each item in the data
58 for item in data:
59 # Check if item is a tuple
60 if not isinstance(item, tuple):
61 raise TypeError("Graph item malformed")
62
63 # Check if tuple is not empty
64 if len(item) == 0:
65 raise TypeError("Graph item malformed")
66
67 # Get the item type
68 item_type = item[0]
69
70 # Process based on item type
71 if item_type == ATTR:
72 if len(item) != 3:
73 raise TypeError("Graph item malformed")
74 _, key, value = item
75 self.attrs[key] = value
76 elif item_type == NODE:
77 if len(item) != 3:
78 raise TypeError("Graph item malformed")
79 _, name, attrs = item
80 self.nodes.append(Node(name, attrs))
81 elif item_type == EDGE:
82 if len(item) != 4:
83 raise TypeError("Graph item malformed")
84 _, src, dst, attrs = item
85 self.edges.append(Edge(src, dst, attrs))
86 else:
87 raise ValueError("Unknown item")
Test NameStatus
test_empty_graph
Fail
test_graph_with_attributes
Pass
test_graph_with_one_attribute
Pass
test_graph_with_one_edge
Pass
test_graph_with_one_node
Pass
test_graph_with_one_node_with_keywords
Pass
test_malformed_EDGE
Pass
test_malformed_attr
Pass
test_malformed_graph
Pass
test_malformed_graph_item
Pass
test_malformed_node
Pass
test_unknown_item
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.