Commits

Jonathan Fine committed 5ece918 Draft

Generate the example file pairs from Blocks (and find a difference with commas).

  • Participants
  • Parent commits 547b393
  • Branches jfine.2012-11-18

Comments (0)

Files changed (1)

File py2/jfine/work.py

 
     def iter_pairs(self, flag, namemap):
 
+        yield ('IF', flag)
         yield ('BEGIN', ' '.join(
                 '{0},'.format(namemap[var])
                 for var in self.variables))
 
 if __name__ == '__main__':
 
+    a_z = dict(zip(range(10), 'abcdefghij'))
     b = Block((0, 1, 2), (3, 4, 'Hello'))
-    for pair in b.iter_pairs(1, dict(zip(range(10), 'abcdefghij'))):
+    for pair in b.iter_pairs(1, a_z):
         print pair
 
+    BLOCKS = (
+        Block((0, 1), ('A', 0, 1, 'C', 2)),
+        Block((2,), ('a',)),
+        Block((0, 2), ('b', 1)),
+        )
+
+    tmp = [('HEADER', None)]
+    for i, block in enumerate(BLOCKS, 1):
+        tmp.extend(block.iter_pairs(i, a_z))
+
+    generated_pairs = tuple(tmp)
+
     pairs = (
         ('HEADER', None),
         ('IF', 1),
         ('END', None),
         )
 
+    for a, b in zip(generated_pairs, pairs):
+        if a != b:
+            print a, b
+
+
     filename = 'py2/jfine/example_template_function.py'
     with open(filename, 'rb') as f:
         expect = f.read()