if conn is not None:
conn_name, conn_number = conn
- if not (isinstance(conn_name, str) and isinstance(conn_number, int)):
- raise TypeError("Connector must be None or a pair of string and integer, not {!r}"
+ if not (isinstance(conn_name, str) and isinstance(conn_number, (int, str))):
+ raise TypeError("Connector must be None or a pair of string (connector name) and "
+ "integer/string (connector number), not {!r}"
.format(conn))
names = ["{}_{}:{}".format(conn_name, conn_number, name) for name in names]
if conn is not None:
conn_name, conn_number = conn
- if not (isinstance(conn_name, str) and isinstance(conn_number, int)):
- raise TypeError("Connector must be None or a pair of string and integer, not {!r}"
+ if not (isinstance(conn_name, str) and isinstance(conn_number, (int, str))):
+ raise TypeError("Connector must be None or a pair of string (connector name) and "
+ "integer/string (connector number), not {!r}"
.format(conn))
for conn_pin, plat_pin in mapping.items():
def test_conn(self):
p = Pins("0 1 2", conn=("pmod", 0))
self.assertEqual(list(p), ["pmod_0:0", "pmod_0:1", "pmod_0:2"])
+ p = Pins("0 1 2", conn=("pmod", "a"))
+ self.assertEqual(list(p), ["pmod_a:0", "pmod_a:1", "pmod_a:2"])
def test_map_names(self):
p = Pins("0 1 2", conn=("pmod", 0))
msg="Direction must be one of \"i\", \"o\", \"oe\", or \"io\", not 'wrong'"):
p = Pins("A0 A1", dir="wrong")
+ def test_wrong_conn(self):
+ with self.assertRaises(TypeError,
+ msg="Connector must be None or a pair of string (connector name) and "
+ "integer/string (connector number), not ('foo', None)"):
+ p = Pins("A0 A1", conn=("foo", None))
+
def test_wrong_map_names(self):
p = Pins("0 1 2", conn=("pmod", 0))
mapping = {
("10", "expansion_0:7"),
]))
+ def test_str_name(self):
+ c = Connector("ext", "A", "0 1 2")
+ self.assertEqual(c.name, "ext")
+ self.assertEqual(c.number, "A")
+
+ def test_conn_wrong_name(self):
+ with self.assertRaises(TypeError,
+ msg="Connector must be None or a pair of string (connector name) and "
+ "integer/string (connector number), not ('foo', None)"):
+ Connector("ext", "A", "0 1 2", conn=("foo", None))
+
def test_wrong_io(self):
with self.assertRaises(TypeError,
msg="Connector I/Os must be a dictionary or a string, not []"):