test_version.py 1.8 KB
Newer Older
M
minqiyang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

15 16
from __future__ import print_function

M
minqiyang 已提交
17 18 19 20 21
import unittest
import re

import paddle.version as fluid_version

M
minqiyang 已提交
22

M
minqiyang 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36
class VersionTest(unittest.TestCase):
    def setUp(self):
        self._major_regex = "[0-9]+"
        self._minor_regex = "[0-9]+"
        self._patch_regex = "[0-9]+(\\.(a|b|rc)\\.[0-9]+)?"
        self._rc_regex = "[0-9]+"
        self._version_regex = "[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?"
        self._commit_regex = "[0-9a-f]{5,49}"

    def test_check_output(self):
        self.assertTrue(isinstance(fluid_version.istaged, bool))

        # check version format
        if fluid_version.istaged:
37
            self.assertEqual(fluid_version.full_version, "latest")
M
minqiyang 已提交
38
        else:
39 40
            # check commit format
            self.assertTrue(re.match(self._commit_regex, fluid_version.commit))
M
minqiyang 已提交
41 42 43 44
            self.assertTrue(re.match(self._major_regex, fluid_version.major))
            self.assertTrue(re.match(self._minor_regex, fluid_version.minor))
            self.assertTrue(re.match(self._patch_regex, fluid_version.patch))
            self.assertTrue(re.match(self._rc_regex, fluid_version.rc))
M
minqiyang 已提交
45 46
            self.assertTrue(
                re.match(self._version_regex, fluid_version.full_version))