add basic test routine for Pin class
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 20 Mar 2018 16:08:50 +0000 (16:08 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Tue, 20 Mar 2018 16:08:50 +0000 (16:08 +0000)
src/interface_decl.py

index 3297f7c71947f5e381a9fcf93084485c7e6b9b03..c66098e55c016696ffeda2d86d53c93c4c50dd45 100644 (file)
@@ -91,8 +91,34 @@ class Pin(object):
         if self.action:
             res += " Action "
         res += self.name
-        if inout:
+        if self.inout:
             res += ' (Bit#(1) in)'
         res += ";"
         return res
 
+
+# basic test
+if __name__ == '__main__':
+
+    def _pinmunge(p, sep, repl, dedupe=True):
+        """ munges the text so it's easier to compare.
+            splits by separator, strips out blanks, re-joins.
+        """
+        p = p.strip()
+        p = p.split(sep)
+        if dedupe:
+            p = filter(lambda x: x, p) # filter out blanks
+        return repl.join(p)
+
+    def pinmunge(p):
+        """ munges the text so it's easier to compare.
+        """
+        p = _pinmunge(p, "(", " ( ", False)
+        p = _pinmunge(p, ")", " ) ", False)
+        p = _pinmunge(p, " ", " ")
+        return p
+
+    pwm = Pin("pwm{0}", True, True, True, True)
+    print pinmunge(str(pwm))
+    print pinmunge(pwminterface_decl)
+    assert pinmunge(str(pwm)) == pinmunge(pwminterface_decl)