From 359b3b2083e4d743097a9b11679493b71b399a84 Mon Sep 17 00:00:00 2001 From: Rahul Nair Date: Tue, 14 Mar 2017 15:56:02 -0500 Subject: [PATCH] Adding unit tests Unit tests added for - checks/time.py Change-Id: I8173305eef349bccdf20abfe59064baf8c03c994 --- tests/unit/test_time_checks.py | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/unit/test_time_checks.py diff --git a/tests/unit/test_time_checks.py b/tests/unit/test_time_checks.py new file mode 100644 index 00000000..19ca8456 --- /dev/null +++ b/tests/unit/test_time_checks.py @@ -0,0 +1,67 @@ +# Copyright 2017 Intel +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import testtools + +import syntribos.checks.time as time_checks +import syntribos.signal + + +class _FakeSignal(object): + + def ran_check(self, check_name): + return True + + +class _FakeElapsedObject(object): + + def __init__(self, seconds): + self.seconds = seconds + + def total_seconds(self): + return self.seconds + + +class _FakeRequestObject(object): + + def __init__(self, seconds=10): + self.request = "request" + self.elapsed = _FakeElapsedObject(seconds) + + +class _FakeTestObject(object): + + def __init__(self, seconds=10, diff=False): + self.init_req = _FakeRequestObject(seconds) # noqa + self.init_resp = _FakeRequestObject(seconds) # noqa + if diff: + seconds += 1000 + self.test_req = _FakeRequestObject(seconds) # noqa + self.test_resp = _FakeRequestObject(seconds) # noqa + self.init_signals = _FakeSignal() + + +class TimeCheckUnittest(testtools.TestCase): + + test_0 = _FakeTestObject() + test_1 = _FakeTestObject(1, diff=True) + + def test_percentage_difference(self): + signal_0 = time_checks.percentage_difference(self.test_0) + signal_1 = time_checks.percentage_difference(self.test_1) + self.assertIsNone(signal_0) + self.assertTrue(isinstance(signal_1, syntribos.signal.SynSignal)) + + def test_absolute_time(self): + signal_0 = time_checks.absolute_time(self.test_0) + self.assertTrue(isinstance(signal_0, syntribos.signal.SynSignal))