Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Zack Williams | 9a42f87 | 2019-02-15 17:56:04 -0700 | [diff] [blame] | 15 | from __future__ import absolute_import |
| 16 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 17 | import os |
| 18 | import unittest |
| 19 | |
| 20 | from xosutil import autodiscover_version |
| 21 | |
| 22 | test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) |
| 23 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 24 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 25 | class XOSUtilTest(unittest.TestCase): |
| 26 | """ |
| 27 | Testing the XOS Util Module |
| 28 | """ |
| 29 | |
| 30 | def setUp(self): |
| 31 | pass |
| 32 | |
| 33 | def tearDown(self): |
| 34 | pass |
| 35 | |
| 36 | def test_autodiscover_version_of_caller(self): |
| 37 | version = open(os.path.join(test_path, "../../../VERSION")).readline().strip() |
| 38 | self.assertEqual(version, autodiscover_version.autodiscover_version_of_caller()) |
| 39 | |
| 40 | def test_autodiscover_version_of_caller_save_to(self): |
| 41 | version = open(os.path.join(test_path, "../../../VERSION")).readline().strip() |
| 42 | test_save_fn = os.path.join(test_path, "test_version.py") |
| 43 | if os.path.exists(test_save_fn): |
| 44 | os.remove(test_save_fn) |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 45 | self.assertEqual( |
| 46 | version, |
| 47 | autodiscover_version.autodiscover_version_of_caller( |
| 48 | save_to="test_version.py" |
| 49 | ), |
| 50 | ) |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 51 | self.assertTrue(os.path.exists(test_save_fn)) |
| 52 | self.assertTrue(version in open(test_save_fn).read()) |
| 53 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 54 | |
Scott Baker | bcbd4cc | 2018-03-07 13:50:21 -0800 | [diff] [blame] | 55 | if __name__ == "__main__": |
| 56 | unittest.main() |