mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 12:06:08 +00:00
test/exec_control: Updated to test new @once functionality
This commit is contained in:
parent
f26d819aad
commit
707b5409e7
@ -25,9 +25,15 @@ from wa.utils.exec_control import (init_environment, reset_environment,
|
|||||||
|
|
||||||
class TestClass(object):
|
class TestClass(object):
|
||||||
|
|
||||||
|
called = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
||||||
|
@once
|
||||||
|
def called_once(self):
|
||||||
|
TestClass.called += 1
|
||||||
|
|
||||||
@once
|
@once
|
||||||
def initilize_once(self):
|
def initilize_once(self):
|
||||||
self.count += 1
|
self.count += 1
|
||||||
@ -101,6 +107,27 @@ class AnotherClass(object):
|
|||||||
self.count += 1
|
self.count += 1
|
||||||
|
|
||||||
|
|
||||||
|
class AnotherSubClass(TestClass):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(AnotherSubClass, self).__init__()
|
||||||
|
|
||||||
|
@once
|
||||||
|
def initilize_once(self):
|
||||||
|
super(AnotherSubClass, self).initilize_once()
|
||||||
|
self.count += 1
|
||||||
|
|
||||||
|
@once_per_class
|
||||||
|
def initilize_once_per_class(self):
|
||||||
|
super(AnotherSubClass, self).initilize_once_per_class()
|
||||||
|
self.count += 1
|
||||||
|
|
||||||
|
@once_per_instance
|
||||||
|
def initilize_once_per_instance(self):
|
||||||
|
super(AnotherSubClass, self).initilize_once_per_instance()
|
||||||
|
self.count += 1
|
||||||
|
|
||||||
|
|
||||||
class EnvironmentManagementTest(TestCase):
|
class EnvironmentManagementTest(TestCase):
|
||||||
|
|
||||||
def test_duplicate_environment(self):
|
def test_duplicate_environment(self):
|
||||||
@ -145,6 +172,17 @@ class EnvironmentManagementTest(TestCase):
|
|||||||
assert_equal(t1.count, 2)
|
assert_equal(t1.count, 2)
|
||||||
|
|
||||||
|
|
||||||
|
class ParentOnlyOnceEvironmentTest(TestCase):
|
||||||
|
def test_sub_classes(self):
|
||||||
|
sc = SubClass()
|
||||||
|
asc = AnotherSubClass()
|
||||||
|
|
||||||
|
sc.called_once()
|
||||||
|
assert_equal(sc.called, 1)
|
||||||
|
asc.called_once()
|
||||||
|
assert_equal(asc.called, 1)
|
||||||
|
|
||||||
|
|
||||||
class OnlyOnceEnvironmentTest(TestCase):
|
class OnlyOnceEnvironmentTest(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -182,17 +220,22 @@ class OnlyOnceEnvironmentTest(TestCase):
|
|||||||
t1 = TestClass()
|
t1 = TestClass()
|
||||||
sc = SubClass()
|
sc = SubClass()
|
||||||
ss = SubSubClass()
|
ss = SubSubClass()
|
||||||
|
asc = AnotherSubClass()
|
||||||
|
|
||||||
t1.initilize_once()
|
t1.initilize_once()
|
||||||
assert_equal(t1.count, 1)
|
assert_equal(t1.count, 1)
|
||||||
|
|
||||||
sc.initilize_once()
|
sc.initilize_once()
|
||||||
sc.initilize_once()
|
sc.initilize_once()
|
||||||
assert_equal(sc.count, 0)
|
assert_equal(sc.count, 1)
|
||||||
|
|
||||||
ss.initilize_once()
|
ss.initilize_once()
|
||||||
ss.initilize_once()
|
ss.initilize_once()
|
||||||
assert_equal(ss.count, 0)
|
assert_equal(ss.count, 1)
|
||||||
|
|
||||||
|
asc.initilize_once()
|
||||||
|
asc.initilize_once()
|
||||||
|
assert_equal(asc.count, 1)
|
||||||
|
|
||||||
|
|
||||||
class OncePerClassEnvironmentTest(TestCase):
|
class OncePerClassEnvironmentTest(TestCase):
|
||||||
@ -234,6 +277,7 @@ class OncePerClassEnvironmentTest(TestCase):
|
|||||||
sc2 = SubClass()
|
sc2 = SubClass()
|
||||||
ss1 = SubSubClass()
|
ss1 = SubSubClass()
|
||||||
ss2 = SubSubClass()
|
ss2 = SubSubClass()
|
||||||
|
asc = AnotherSubClass()
|
||||||
|
|
||||||
t1.initilize_once_per_class()
|
t1.initilize_once_per_class()
|
||||||
assert_equal(t1.count, 1)
|
assert_equal(t1.count, 1)
|
||||||
@ -248,6 +292,9 @@ class OncePerClassEnvironmentTest(TestCase):
|
|||||||
assert_equal(ss1.count, 1)
|
assert_equal(ss1.count, 1)
|
||||||
assert_equal(ss2.count, 0)
|
assert_equal(ss2.count, 0)
|
||||||
|
|
||||||
|
asc.initilize_once_per_class()
|
||||||
|
assert_equal(asc.count, 1)
|
||||||
|
|
||||||
|
|
||||||
class OncePerInstanceEnvironmentTest(TestCase):
|
class OncePerInstanceEnvironmentTest(TestCase):
|
||||||
|
|
||||||
@ -286,6 +333,7 @@ class OncePerInstanceEnvironmentTest(TestCase):
|
|||||||
t1 = TestClass()
|
t1 = TestClass()
|
||||||
sc = SubClass()
|
sc = SubClass()
|
||||||
ss = SubSubClass()
|
ss = SubSubClass()
|
||||||
|
asc = AnotherSubClass()
|
||||||
|
|
||||||
t1.initilize_once_per_instance()
|
t1.initilize_once_per_instance()
|
||||||
assert_equal(t1.count, 1)
|
assert_equal(t1.count, 1)
|
||||||
@ -297,3 +345,7 @@ class OncePerInstanceEnvironmentTest(TestCase):
|
|||||||
ss.initilize_once_per_instance()
|
ss.initilize_once_per_instance()
|
||||||
ss.initilize_once_per_instance()
|
ss.initilize_once_per_instance()
|
||||||
assert_equal(ss.count, 3)
|
assert_equal(ss.count, 3)
|
||||||
|
|
||||||
|
asc.initilize_once_per_instance()
|
||||||
|
asc.initilize_once_per_instance()
|
||||||
|
assert_equal(asc.count, 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user