def test_with_block_exception(self): pyrtl.set_working_block(self.block_a) with self.assertRaises(pyrtl.PyrtlInternalError): with pyrtl.set_working_block(self.block_b): self.assertIs(pyrtl.working_block(), self.block_b) raise pyrtl.PyrtlInternalError() self.assertIs(pyrtl.working_block(), self.block_a)
def test_with_block_nested(self): self.block_c = pyrtl.Block() pyrtl.set_working_block(self.block_a) self.assertIs(pyrtl.working_block(), self.block_a) with pyrtl.set_working_block(self.block_b): self.assertIs(pyrtl.working_block(), self.block_b) with pyrtl.set_working_block(self.block_c): self.assertIs(pyrtl.working_block(), self.block_c) self.assertIs(pyrtl.working_block(), self.block_b) self.assertIs(pyrtl.working_block(), self.block_a)
def test_invalid_with_set_wb(self): x = pyrtl.Input() y = True pyrtl.set_working_block(self.block_a) with self.assertRaises(pyrtl.PyrtlError): with pyrtl.set_working_block(x): pass self.assertEqual(pyrtl.working_block(), self.block_a) with self.assertRaises(pyrtl.PyrtlError): with pyrtl.set_working_block(y): pass self.assertEqual(pyrtl.working_block(), self.block_a)
def test_clone_wire_no_or_same_name_different_block(self): for clone_name in (None, 'a'): a = pyrtl.WireVector(1, 'a') b = pyrtl.Block() with pyrtl.set_working_block(b): w = pyrtl.clone_wire(a, name=clone_name) self.assertEqual(a.name, 'a') self.assertIs(pyrtl.working_block().wirevector_by_name['a'], a) self.assertEqual(pyrtl.working_block().wirevector_set, {a}) self.assertEqual(w.name, 'a') self.assertIs(b.wirevector_by_name['a'], w) self.assertEqual(b.wirevector_set, {w}) pyrtl.reset_working_block()
def test_invalid_set_wb(self): x = pyrtl.WireVector() y = 1 pyrtl.set_working_block(self.block_a) with self.assertRaises(pyrtl.PyrtlError): pyrtl.set_working_block(x) self.assertEqual(pyrtl.working_block(), self.block_a) with self.assertRaises(pyrtl.PyrtlError): pyrtl.set_working_block(y) self.assertEqual(pyrtl.working_block(), self.block_a)
def test_with_block(self): pyrtl.set_working_block(self.block_a) self.assertIs(pyrtl.working_block(), self.block_a) with pyrtl.set_working_block(self.block_b): self.assertIs(pyrtl.working_block(), self.block_b) self.assertIs(pyrtl.working_block(), self.block_a)
def test_normal(self): pyrtl.set_working_block(self.block_a) self.assertIs(pyrtl.working_block(), self.block_a) pyrtl.set_working_block(self.block_b) self.assertIs(pyrtl.working_block(), self.block_b)