Пример #1
0
 def test__contains__7(self):
     edges = edges_.Edges(
         ['pq', 'rs'])  # yes, quite strange, so I just warn you here...
     self.assertIn('pq',
                   edges)  # yes, quite strange, so I just warn you here...
     self.assertIn('rs',
                   edges)  # yes, quite strange, so I just warn you here...
Пример #2
0
 def test__has_neighbors(self):
     edges = edges_.Edges([('p', 'q'), ('q', 'r'), ('s', 'r')])
     self.assertTrue(edges.has_neighbors('p'))
     self.assertTrue(edges.has_neighbors('q'))
     self.assertTrue(edges.has_neighbors('r'))
     self.assertTrue(edges.has_neighbors('s'))
     self.assertFalse(edges.has_neighbors('x'))
Пример #3
0
 def test__init__5(self):
     edges = edges_.Edges({'s1': 'E1', 's2': 'E2'})
     self.assertEqual(edges.data, {('s', '1'): 'E1', ('s', '2'): 'E2'})
     self.assertEqual(edges.successors_dict, {'s': set(('1', '2'))})
     self.assertEqual(edges.predecessors_dict, {
         '1': set(('s', )),
         '2': set(('s', ))
     })
Пример #4
0
    def test__setitem__ValueError_2(self):
        edges = edges_.Edges()
        with self.assertRaises(ValueError) as context:
            edges[('p', 'q', 'r')] = 'E1'
##        self.assertIn("too many values to unpack", str(context.exception))
        self.assertEqual(edges.data, dict())
        self.assertEqual(edges.successors_dict, dict())
        self.assertEqual(edges.predecessors_dict, dict())
Пример #5
0
    def test__add__ValueError_1(self):
        edges = edges_.Edges()
        with self.assertRaises(ValueError) as context:
            edges.add(('p', ))
##        self.assertIn("not enough values to unpack", str(context.exception))
        self.assertEqual(edges.data, dict())
        self.assertEqual(edges.successors_dict, dict())
        self.assertEqual(edges.predecessors_dict, dict())
Пример #6
0
 def test__inward__2(self):
     edges = edges_.Edges([('p', 'q'), ('q', 'r'), ('s', 'r')])
     self.assertEqual(edges.inward('p'), set())
     self.assertEqual(edges.inward('q'), set([
         ('p', 'q'),
     ]))
     self.assertEqual(edges.inward('r'), set([('q', 'r'), ('s', 'r')]))
     self.assertEqual(edges.inward('s'), set())
Пример #7
0
 def test__init__2(self):
     edges = edges_.Edges([('s1', 't1'), ('s2', 't2'), ('s1', 't1')])
     self.assertEqual(edges.data, {('s1', 't1'): None, ('s2', 't2'): None})
     self.assertEqual(edges.successors_dict, {
         's1': set(('t1', )),
         's2': set(('t2', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         't1': set(('s1', )),
         't2': set(('s2', ))
     })
Пример #8
0
 def test__init__5_data_false(self):
     edges = edges_.Edges({'s1': 't1', 's2': 't2'}, data=False)
     self.assertEqual(edges.data, {('s1', 't1'): None, ('s2', 't2'): None})
     self.assertEqual(edges.successors_dict, {
         's1': set(('t1', )),
         's2': set(('t2', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         't1': set(('s1', )),
         't2': set(('s2', ))
     })
Пример #9
0
 def test__discard__2(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     edges.discard(('r', 'p'))
     self.assertEqual(edges.data, {('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(edges.successors_dict, {
         'p': set(('q', )),
         'q': set(('r', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         'q': set(('p', )),
         'r': set(('q', ))
     })
Пример #10
0
 def test__init__3_edgedata_true(self):
     edges = edges_.Edges([(('s1', 't1'), 'E1'), (('s2', 't2'), 'E2')],
                          edgedata=True)
     self.assertEqual(edges.data, {('s1', 't1'): 'E1', ('s2', 't2'): 'E2'})
     self.assertEqual(edges.successors_dict, {
         's1': set(('t1', )),
         's2': set(('t2', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         't1': set(('s1', )),
         't2': set(('s2', ))
     })
Пример #11
0
 def test__del_incident__1(self):
     edges = edges_.Edges([('p', 'q'), ('q', 'r'), ('s', 'q')])
     edges.del_incident('s')
     self.assertEqual(edges.data, {('p', 'q'): None, ('q', 'r'): None})
     self.assertEqual(edges.successors_dict, {
         'p': set(('q', )),
         'q': set(('r', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         'q': set(('p', )),
         'r': set(('q', ))
     })
Пример #12
0
 def test__setitem__2(self):
     edges = edges_.Edges({('p', 'q'): 'E1'})
     edges[('p', 'q')] = '_E1_'
     edges[('q', 'r')] = '_E2_'
     self.assertEqual(edges.data, {('p', 'q'): '_E1_', ('q', 'r'): '_E2_'})
     self.assertEqual(edges.successors_dict, {
         'p': set(('q', )),
         'q': set(('r', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         'q': set(('p', )),
         'r': set(('q', ))
     })
Пример #13
0
 def test__add__1(self):
     edges = edges_.Edges({('p', 'q'): 'E1'})
     edges.add(('p', 'q'), '_E1_')
     edges.add(('q', 'r'), '_E2_')
     self.assertEqual(edges.data, {('p', 'q'): '_E1_', ('q', 'r'): '_E2_'})
     self.assertEqual(edges.successors_dict, {
         'p': set(('q', )),
         'q': set(('r', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         'q': set(('p', )),
         'r': set(('q', ))
     })
Пример #14
0
 def test__delitem__KeyError_4(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     with self.assertRaises(KeyError) as context:
         del edges[('p', 'q', 'r')]
     self.assertEqual(repr(('p', 'q', 'r')), str(context.exception))
     self.assertEqual(edges.data, {('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(edges.successors_dict, {
         'p': set(('q', )),
         'q': set(('r', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         'q': set(('p', )),
         'r': set(('q', ))
     })
Пример #15
0
 def test__init__4_edgedata_false_data_true(self):
     edges = edges_.Edges({
         ('r1', 's1'): 't1',
         ('r2', 's2'): 't2'
     },
                          edgedata=False,
                          data=True)
     self.assertEqual(edges.data, {
         (('r1', 's1'), 't1'): None,
         (('r2', 's2'), 't2'): None
     })
     self.assertEqual(edges.successors_dict, {
         ('r1', 's1'): set(('t1', )),
         ('r2', 's2'): set(('t2', ))
     })
     self.assertEqual(edges.predecessors_dict, {
         't1': set((('r1', 's1'), )),
         't2': set((('r2', 's2'), ))
     })
Пример #16
0
 def test__items(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(list(edges.items()), list(edges.data.items()))
Пример #17
0
 def test__getitem__2(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('r', 's'): 'E2'})
     self.assertEqual(edges['pq'], 'E1')
     self.assertEqual(edges['rs'], 'E2')
Пример #18
0
 def test__contains__6(self):
     edges = edges_.Edges([('p', 'q'), ('r', 's')])
     self.assertIn('pq',
                   edges)  # yes, quite strange, so I just warn you here...
     self.assertIn('rs',
                   edges)  # yes, quite strange, so I just warn you here...
Пример #19
0
 def test__clear(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     edges.clear()
     self.assertEqual(edges.data, dict())
     self.assertEqual(edges.successors_dict, dict())
     self.assertEqual(edges.predecessors_dict, dict())
Пример #20
0
 def test__len__(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(len(edges), 2)
Пример #21
0
 def test__iter__(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(list(iter(edges)), list(iter(edges.data)))
Пример #22
0
 def test__repr__1(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(repr(edges), "Edges(%s)" % repr(edges.data))
Пример #23
0
 def test__delitem__1(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     del edges[('p', 'q')]
     self.assertEqual(edges.data, {('q', 'r'): 'E2'})
     self.assertEqual(edges.successors_dict, {'q': set(('r', ))})
     self.assertEqual(edges.predecessors_dict, {'r': set(('q', ))})
Пример #24
0
 def test__repr__2(self):
     edges = edges_.Edges()
     self.assertEqual(repr(edges), "Edges()")
Пример #25
0
 def test__getitem__1(self):
     edges = edges_.Edges({('p', 'q'): 'E1', ('q', 'r'): 'E2'})
     self.assertEqual(edges[('p', 'q')], 'E1')
     self.assertEqual(edges[('q', 'r')], 'E2')
Пример #26
0
 def test__del_incident__2(self):
     edges = edges_.Edges([('p', 'q'), ('q', 'r'), ('s', 'q')])
     edges.del_incident('q')
     self.assertEqual(edges.data, dict())
     self.assertEqual(edges.successors_dict, dict())
     self.assertEqual(edges.predecessors_dict, dict())
Пример #27
0
 def test__del_incident__KeyError(self):
     edges = edges_.Edges([('p', 'q'), ('q', 'r')])
     with self.assertRaises(KeyError) as context:
         edges.del_incident('s')
     self.assertEqual(repr('s'), str(context.exception))
Пример #28
0
 def test__getitem__KeyError_3(self):
     edges = edges_.Edges()
     with self.assertRaises(KeyError) as context:
         edges['pq']
     self.assertEqual(repr('pq'), str(context.exception))
Пример #29
0
 def test__init__0(self):
     edges = edges_.Edges()
     self.assertEqual(edges.data, dict())
     self.assertEqual(edges.successors_dict, dict())
     self.assertEqual(edges.predecessors_dict, dict())
Пример #30
0
 def test__getitem__KeyError_5(self):
     edges = edges_.Edges([('p', 'q'), ('q', 'r')])
     with self.assertRaises(KeyError) as context:
         edges[('p', 'q', 'r')]
     self.assertEqual(repr(('p', 'q', 'r')), str(context.exception))