Ejemplo n.º 1
0
 def _get_transform(self, resource, reverse):
     type = resource['!type']
     if type not in self._cache:
         if reverse:
             for col in application.collections.values():
                 proc = ArgumentProcessor(ignore_missing=True)
                 proc.rules(col.entity_transform)
                 result = proc.process({'!type': col.contains})
                 if result.get('!type') == type:
                     break
             else:
                 col = None
         else:
             for col in application.collections.values():
                 if col.contains == type:
                     break
             else:
                 col = None
         if col and getattr(col, 'entity_transform', None):
             proc = ArgumentProcessor()
             proc.namespace = self._get_namespace(col)
             proc.tags = self._get_tags(col, resource)
             proc.rules(col.entity_transform)
         else:
             proc = None
         self._cache[type] = proc
     proc = self._cache[type]
     return proc
Ejemplo n.º 2
0
 def test_multiple_rules(self):
     proc = ArgProc()
     proc.rules("""
         $left1 <=> $right1
         $left2 <=> $right2
         """)
     right = proc.process({'left1': 1, 'left2': 2})
     assert right == {'right1': 1, 'right2': 2}
Ejemplo n.º 3
0
 def test_multiple_rules(self):
     proc = ArgProc()
     proc.rules("""
         $left1 <=> $right1
         $left2 <=> $right2
         """)
     right = proc.process({'left1': 1, 'left2': 2})
     assert right== {'right1': 1, 'right2': 2}
Ejemplo n.º 4
0
 def test_comment(self):
     proc = ArgProc()
     proc.rules("""
             $left1 => $right1  # comment
             #$left2 => $right2
     """)
     assert proc.process({'left1': 10}) == {'right1': 10}
     assert proc.process({'left2': 20}) == {}
Ejemplo n.º 5
0
 def test_comment(self):
     proc = ArgProc()
     proc.rules("""
             $left1 => $right1  # comment
             #$left2 => $right2
     """)
     assert proc.process({'left1': 10}) == {'right1': 10}
     assert proc.process({'left2': 20}) == {}