tests: replace pycodestyle with black
[vpp.git] / src / tools / vppapigen / test_vppapigen.py
index c454ffc..20f6c6d 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/env python3
 
 import unittest
-from vppapigen import VPPAPI, Option, ParseError, Union, foldup_crcs, \
-    global_types
+from vppapigen import VPPAPI, Option, ParseError, Union, foldup_crcs, global_types
 import vppapigen
 
 
@@ -28,17 +27,17 @@ class TestUnion(unittest.TestCase):
         cls.parser = VPPAPI()
 
     def test_union(self):
-        test_string = '''
+        test_string = """
         union foo_union {
         u32 a;
         u8 b;
         };
-        '''
+        """
         r = self.parser.parse_string(test_string)
         self.assertTrue(isinstance(r[0], Union))
 
     def test_union_vla(self):
-        test_string = '''
+        test_string = """
         union foo_union_vla {
         u32 a;
         u8 b[a];
@@ -46,13 +45,13 @@ class TestUnion(unittest.TestCase):
         autoreply define foo {
         vl_api_foo_union_vla_t v;
         };
-        '''
+        """
         r = self.parser.parse_string(test_string)
         self.assertTrue(isinstance(r[0], Union))
         self.assertTrue(r[0].vla)
         s = self.parser.process(r)
 
-        test_string2 = '''
+        test_string2 = """
         union foo_union_vla2 {
         u32 a;
         u8 b[a];
@@ -61,10 +60,10 @@ class TestUnion(unittest.TestCase):
         autoreply define foo2 {
         vl_api_foo_union_vla2_t v;
         };
-        '''
+        """
         self.assertRaises(ValueError, self.parser.parse_string, test_string2)
 
-        test_string3 = '''
+        test_string3 = """
         union foo_union_vla3 {
         u32 a;
         u8 b[a];
@@ -73,7 +72,7 @@ class TestUnion(unittest.TestCase):
         vl_api_foo_union_vla3_t v;
         u32 x;
         };
-        '''
+        """
         self.assertRaises(ValueError, self.parser.parse_string, test_string3)
 
 
@@ -83,10 +82,10 @@ class TestTypedef(unittest.TestCase):
         cls.parser = VPPAPI()
 
     def test_duplicatetype(self):
-        test_string = '''
+        test_string = """
         typedef foo1 { u8 dummy; };
         typedef foo1 { u8 dummy; };
-        '''
+        """
         self.assertRaises(KeyError, self.parser.parse_string, test_string)
 
 
@@ -96,42 +95,42 @@ class TestDefine(unittest.TestCase):
         cls.parser = VPPAPI()
 
     def test_unknowntype(self):
-        test_string = 'define foo { foobar foo;};'
+        test_string = "define foo { foobar foo;};"
         with self.assertRaises(ParseError) as ctx:
             self.parser.parse_string(test_string)
-        self.assertIn('Undefined type: foobar', str(ctx.exception))
+        self.assertIn("Undefined type: foobar", str(ctx.exception))
 
-        test_string = 'define { u8 foo;};'
+        test_string = "define { u8 foo;};"
         with self.assertRaises(ParseError) as ctx:
             self.parser.parse_string(test_string)
 
     def test_flags(self):
-        test_string = '''
+        test_string = """
           manual_print dont_trace manual_endian define foo { u8 foo; };
           define foo_reply {u32 context; i32 retval; };
-        '''
+        """
         r = self.parser.parse_string(test_string)
         self.assertIsNotNone(r)
         s = self.parser.process(r)
         self.assertIsNotNone(s)
-        for d in s['Define']:
-            if d.name == 'foo':
+        for d in s["Define"]:
+            if d.name == "foo":
                 self.assertTrue(d.dont_trace)
                 self.assertTrue(d.manual_endian)
                 self.assertTrue(d.manual_print)
                 self.assertFalse(d.autoreply)
 
-        test_string = '''
+        test_string = """
           nonexisting_flag define foo { u8 foo; };
-        '''
+        """
         with self.assertRaises(ParseError):
             self.parser.parse_string(test_string)
 
     def test_options(self):
-        test_string = '''
+        test_string = """
           define foo { option deprecated; u8 foo; };
           define foo_reply {u32 context; i32 retval; };
-        '''
+        """
         r = self.parser.parse_string(test_string)
         self.assertIsNotNone(r)
         s = self.parser.process(r)
@@ -144,14 +143,14 @@ class TestService(unittest.TestCase):
         cls.parser = VPPAPI()
 
     def test_service(self):
-        test_string = '''
+        test_string = """
          autoreply define show_version { u8 foo;};
          service { rpc show_version returns show_version_reply; };
-        '''
+        """
         r = self.parser.parse_string(test_string)
         s = self.parser.process(r)
-        self.assertEqual(s['Service'][0].caller, 'show_version')
-        self.assertEqual(s['Service'][0].reply, 'show_version_reply')
+        self.assertEqual(s["Service"][0].caller, "show_version")
+        self.assertEqual(s["Service"][0].reply, "show_version_reply")
 
 
 def get_crc(apistring, name):
@@ -159,52 +158,52 @@ def get_crc(apistring, name):
     parser = vppapigen.VPPAPI()
     r = parser.parse_string(apistring)
     s = parser.process(r)
-    foldup_crcs(s['Define'])
-    d = [f for f in s['Define'] if f.name == name]
+    foldup_crcs(s["Define"])
+    d = [f for f in s["Define"] if f.name == name]
     return d[0].crc
 
 
 class TestCRC(unittest.TestCase):
     def test_crc(self):
-        test_string = '''
+        test_string = """
          typedef list { u8 foo; };
          autoreply define foo { u8 foo; vl_api_list_t l;};
-        '''
-        crc = get_crc(test_string, 'foo')
+        """
+        crc = get_crc(test_string, "foo")
 
         # modify underlying type
-        test_string = '''
+        test_string = """
          typedef list { u8 foo2; };
          autoreply define foo { u8 foo;  vl_api_list_t l;};
-        '''
-        crc2 = get_crc(test_string, 'foo')
+        """
+        crc2 = get_crc(test_string, "foo")
         self.assertNotEqual(crc, crc2)
 
         # two user-defined types
-        test_string = '''
+        test_string = """
          typedef address { u8 foo2; };
          typedef list { u8 foo2; vl_api_address_t add; };
          autoreply define foo { u8 foo;  vl_api_list_t l;};
-        '''
-        crc3 = get_crc(test_string, 'foo')
+        """
+        crc3 = get_crc(test_string, "foo")
 
-        test_string = '''
+        test_string = """
          typedef address { u8 foo3; };
          typedef list { u8 foo2; vl_api_address_t add; };
          autoreply define foo { u8 foo;  vl_api_list_t l;};
-        '''
-        crc4 = get_crc(test_string, 'foo')
+        """
+        crc4 = get_crc(test_string, "foo")
         self.assertNotEqual(crc3, crc4)
 
-        test_string = '''
+        test_string = """
          typedef address { u8 foo3; };
          typedef list { u8 foo2; vl_api_address_t add; u8 foo3; };
          autoreply define foo { u8 foo;  vl_api_list_t l;};
-        '''
-        crc5 = get_crc(test_string, 'foo')
+        """
+        crc5 = get_crc(test_string, "foo")
         self.assertNotEqual(crc4, crc5)
 
-        test_string = '''
+        test_string = """
 typedef ip6_address
 {
   u8 foo;
@@ -227,11 +226,11 @@ autoreply define sr_policy_add
   u32 fib_table;
   vl_api_srv6_sid_list_t sids;
 };
-'''
+"""
 
-        crc = get_crc(test_string, 'sr_policy_add')
+        crc = get_crc(test_string, "sr_policy_add")
 
-        test_string = '''
+        test_string = """
 typedef ip6_address
 {
   u8 foo;
@@ -253,14 +252,13 @@ autoreply define sr_policy_add
   u32 fib_table;
   vl_api_srv6_sid_list_t sids;
 };
-'''
-        crc2 = get_crc(test_string, 'sr_policy_add')
+"""
+        crc2 = get_crc(test_string, "sr_policy_add")
 
         self.assertNotEqual(crc, crc2)
 
 
 class TestEnum(unittest.TestCase):
-
     @classmethod
     def setUpClass(cls):
         cls.parser = VPPAPI()
@@ -278,8 +276,8 @@ enum tunnel_mode : u8
         r = self.parser.parse_string(test_string)
         self.assertIsNotNone(r)
         s = self.parser.process(r)
-        for o in s['types']:
-            if o.type == 'Enum':
+        for o in s["types"]:
+            if o.type == "Enum":
                 self.assertEqual(o.name, "tunnel_mode")
                 break
         else:
@@ -298,8 +296,8 @@ enum virtio_flags {
         r = self.parser.parse_string(test_string)
         self.assertIsNotNone(r)
         s = self.parser.process(r)
-        for o in s['types']:
-            if o.type == 'Enum':
+        for o in s["types"]:
+            if o.type == "Enum":
                 self.assertEqual(o.name, "virtio_flags")
                 break
         else:
@@ -307,7 +305,6 @@ enum virtio_flags {
 
 
 class TestEnumFlag(unittest.TestCase):
-
     @classmethod
     def setUpClass(cls):
         cls.parser = VPPAPI()
@@ -326,8 +323,9 @@ enumflag tunnel_mode_ef : u8
         with self.assertRaises(TypeError) as ctx:
             r = self.parser.parse_string(test_string)
 
-        self.assertTrue(str(ctx.exception).startswith(
-            'tunnel_mode_ef is not a flag enum.'))
+        self.assertTrue(
+            str(ctx.exception).startswith("tunnel_mode_ef is not a flag enum.")
+        )
 
     def test_enumflag_as_enumflag(self):
         test_string = """\
@@ -342,13 +340,13 @@ enumflag virtio_flags_ef {
         r = self.parser.parse_string(test_string)
         self.assertIsNotNone(r)
         s = self.parser.process(r)
-        for o in s['types']:
-            if o.type == 'EnumFlag':
+        for o in s["types"]:
+            if o.type == "EnumFlag":
                 self.assertEqual(o.name, "virtio_flags_ef")
                 break
         else:
             self.fail()
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     unittest.main(verbosity=2)