[SEBA-412] Automated reformat of Python code
Passes of modernize, autopep8, black, then check with flake8
flake8 + manual fixes:
lib/xos-config
lib/xos-kafka
lib/xos-util
xos/coreapi
xos/api
xos/xos_client
Change-Id: Ib23cf84cb13beb3c6381fa0d79594dc9131dc815
diff --git a/lib/xos-genx/xos-genx-tests/test_policy.py b/lib/xos-genx/xos-genx-tests/test_policy.py
index d83ab6c..e8b5a76 100644
--- a/lib/xos-genx/xos-genx-tests/test_policy.py
+++ b/lib/xos-genx/xos-genx-tests/test_policy.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,10 +23,10 @@
into Python, set up an appropriate environment and execute the Python.
"""
+
class XProtoPolicyTest(unittest.TestCase):
def test_annotation(self):
- xproto = \
-"""
+ xproto = """
policy true_policy < True >
message always::true_policy {
@@ -45,8 +44,7 @@
self.assertIn("true_policy", output)
def test_constant(self):
- xproto = \
-"""
+ xproto = """
policy true_policy < True >
"""
@@ -56,12 +54,11 @@
args.inputs = xproto
args.target = target
- output = XOSProcessor.process(args).replace('t','T')
- self.assertTrue(eval(output))
+ output = XOSProcessor.process(args).replace("t", "T")
+ self.assertTrue(eval(output))
def test_function_term(self):
- xproto = \
-"""
+ xproto = """
policy slice_user < slice.user.compute_is_admin() >
"""
@@ -71,7 +68,7 @@
args.target = target
output = XOSProcessor.process(args)
-
+
slice = FakeObject()
slice.user = FakeObject()
slice.user.compute_is_admin = lambda: True
@@ -80,8 +77,7 @@
self.assertTrue(expr)
def test_term(self):
- xproto = \
-"""
+ xproto = """
policy slice_user < slice.user.is_admin >
"""
@@ -91,7 +87,7 @@
args.target = target
output = XOSProcessor.process(args)
-
+
slice = FakeObject()
slice.user = FakeObject()
slice.user.is_admin = True
@@ -100,8 +96,7 @@
self.assertTrue(expr)
def test_num_constant(self):
- xproto = \
-"""
+ xproto = """
policy slice_user < slice.user.age = 57 >
"""
@@ -111,7 +106,7 @@
args.target = target
output = XOSProcessor.process(args)
-
+
slice = FakeObject()
slice.user = FakeObject()
slice.user.is_admin = True
@@ -120,8 +115,7 @@
self.assertTrue(expr)
def test_string_constant(self):
- xproto = \
-"""
+ xproto = """
policy slice_user < slice.user.email = "admin@opencord.org" >
"""
@@ -131,7 +125,7 @@
args.target = target
output = XOSProcessor.process(args)
-
+
slice = FakeObject()
slice.user = FakeObject()
slice.user.is_admin = True
@@ -140,8 +134,7 @@
self.assertTrue(expr)
def test_equal(self):
- xproto = \
-"""
+ xproto = """
policy slice_user < slice.user = obj.user >
"""
@@ -151,20 +144,19 @@
args.target = target
output = XOSProcessor.process(args)
-
+
slice = FakeObject()
- slice.user = 'twin'
+ slice.user = "twin"
obj = FakeObject()
- obj.user = 'twin'
+ obj.user = "twin"
(op, operands), = eval(output).items()
- expr = op.join(operands).replace('=','==')
+ expr = op.join(operands).replace("=", "==")
self.assertTrue(eval(expr))
def test_bin(self):
- xproto = \
-"""
+ xproto = """
policy slice_admin < slice.is_admin | obj.empty >
"""
target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.slice_admin }}")
@@ -180,13 +172,12 @@
obj.empty = []
(op, operands), = eval(output).items()
- expr = op.join(operands).replace('|',' or ')
+ expr = op.join(operands).replace("|", " or ")
self.assertFalse(eval(expr))
def test_implies(self):
- xproto = \
-"""
+ xproto = """
policy implies < obj.name -> obj.creator >
"""
target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.implies }}")
@@ -199,17 +190,16 @@
slice = FakeObject()
slice.is_admin = False
obj = FakeObject()
- obj.name = 'Thing 1'
+ obj.name = "Thing 1"
obj.creator = None
(op, operands), = eval(output).items()
- expr = 'not ' + op.join(operands).replace('->',' or ')
+ expr = "not " + op.join(operands).replace("->", " or ")
self.assertFalse(eval(expr))
-
+
def test_exists(self):
- xproto = \
-"""
+ xproto = """
policy privilege < exists Privilege: Privilege.object_id = obj.id >
"""
@@ -219,7 +209,7 @@
args.target = target
output = XOSProcessor.process(args)
-
+
Privilege = FakeObject()
Privilege.object_id = 1
obj = FakeObject()
@@ -227,49 +217,49 @@
(op, operands), = eval(output).items()
(op2, operands2), = operands[1].items()
- expr = op2.join(operands2).replace('=','==')
+ expr = op2.join(operands2).replace("=", "==")
self.assertTrue(eval(expr))
def test_policy_function(self):
- xproto = \
-"""
+ xproto = """
policy slice_policy < exists Privilege: Privilege.object_id = obj.id >
policy network_slice_policy < *slice_policy(slice) >
"""
- target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.network_slice_policy }} ")
+ target = XProtoTestHelpers.write_tmp_target(
+ "{{ proto.policies.network_slice_policy }} "
+ )
args = XOSProcessorArgs()
args.inputs = xproto
args.target = target
output = XOSProcessor.process(args)
-
+
(op, operands), = eval(output).items()
- self.assertIn('slice_policy', operands)
- self.assertIn('slice', operands)
+ self.assertIn("slice_policy", operands)
+ self.assertIn("slice", operands)
def test_policy_missing_function(self):
- xproto = \
-"""
+ xproto = """
policy slice_policy < exists Privilege: Privilege.object_id = obj.id >
policy network_slice_policy < *slice_policyX(slice) >
"""
- target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.network_slice_policy }} ")
+ target = XProtoTestHelpers.write_tmp_target(
+ "{{ proto.policies.network_slice_policy }} "
+ )
args = XOSProcessorArgs()
args.inputs = xproto
args.target = target
with self.assertRaises(Exception):
output = XOSProcessor.process(args)
-
def test_forall(self):
# This one we only parse
- xproto = \
-"""
+ xproto = """
policy instance < forall Instance: exists Credential: Credential.obj_id = Instance.obj_id >
"""
@@ -282,10 +272,8 @@
output = XOSProcessor.process(args)
(op, operands), = eval(output).items()
- self.assertEqual(op,'forall')
+ self.assertEqual(op, "forall")
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()
-
-