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