|
| 1 | +# |
| 2 | +# Copyright (2021) The Delta Lake Project Authors. |
| 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 | + |
| 17 | +import os |
| 18 | +import unittest |
| 19 | +from packaging.version import Version |
| 20 | + |
| 21 | + |
| 22 | +class VersionAPITests(unittest.TestCase): |
| 23 | + |
| 24 | + @classmethod |
| 25 | + def setUpClass(cls): |
| 26 | + cls.project_root = os.path.abspath( |
| 27 | + os.path.join(os.path.dirname(__file__), '..', '..', '..') |
| 28 | + ) |
| 29 | + cls.version_sbt_path = os.path.join(cls.project_root, 'version.sbt') |
| 30 | + |
| 31 | + def verify_version(self, version): |
| 32 | + self.assertIsNotNone(version) |
| 33 | + self.assertIsInstance(version, str) |
| 34 | + self.assertEqual(version.count("."), 2, "Version should have major.minor.patch format") |
| 35 | + # version should be parseable by packaging.version.Version |
| 36 | + Version(version) |
| 37 | + |
| 38 | + def test_version_import_from_module(self): |
| 39 | + """Test that __version__ can be imported from delta.version""" |
| 40 | + from delta.version import __version__ |
| 41 | + self.verify_version(__version__) |
| 42 | + |
| 43 | + def test_version_import_from_package(self): |
| 44 | + """Test that __version__ can be imported from delta package""" |
| 45 | + from delta import __version__ |
| 46 | + self.verify_version(__version__) |
| 47 | + |
| 48 | + def test_version_consistency_across_imports(self): |
| 49 | + """Test that version is consistent across import methods""" |
| 50 | + from delta.version import __version__ as version_from_module |
| 51 | + from delta import __version__ as version_from_package |
| 52 | + |
| 53 | + self.assertEqual(version_from_module, version_from_package) |
| 54 | + |
| 55 | + def test_version_sbt_exists(self): |
| 56 | + """Verify version.sbt exists""" |
| 57 | + self.assertTrue( |
| 58 | + os.path.exists(self.version_sbt_path), |
| 59 | + f"version.sbt not found at {self.version_sbt_path}" |
| 60 | + ) |
| 61 | + |
| 62 | + def test_version_sbt_and_version_py_consistency(self): |
| 63 | + with open(self.version_sbt_path) as f: |
| 64 | + sbt_content = f.read() |
| 65 | + # Extract version from: ThisBuild / version := "x.y.z-SNAPSHOT" -> "x.y.z" |
| 66 | + sbt_version = sbt_content.split('"')[1].removesuffix("-SNAPSHOT") |
| 67 | + |
| 68 | + from delta import __version__ |
| 69 | + |
| 70 | + self.assertEqual( |
| 71 | + __version__, |
| 72 | + sbt_version, |
| 73 | + f"version.py ({__version__}) does not match version.sbt ({sbt_version}). " |
| 74 | + f"Run: build/sbt sparkV1/generatePythonVersion" |
| 75 | + ) |
| 76 | + |
| 77 | + |
| 78 | +if __name__ == '__main__': |
| 79 | + unittest.main() |
0 commit comments