1# 2# Copyright (C) 2024 The Android Open Source Project 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"""Unit tests for base_updater.""" 17 18import unittest 19from pathlib import Path 20 21import base_updater 22# pylint: disable=import-error 23import metadata_pb2 # type: ignore 24# pylint: enable=import-error 25 26 27class UpdaterTest(unittest.TestCase): 28 """Unit tests for Updater.""" 29 30 def test_current_version(self) -> None: 31 """Tests that Updater.current_version returns the appropriate value.""" 32 updater = base_updater.Updater( 33 # This is absolute so we get the fast path out of the path canonicalization 34 # that would otherwise require us to define ANDROID_BUILD_TOP or run from a 35 # temp repo tree. 36 Path("/"), 37 metadata_pb2.Identifier(), 38 "old version", 39 ) 40 self.assertEqual(updater.current_version, "old version") 41 42 identifier = metadata_pb2.Identifier() 43 identifier.version = "old version" 44 updater = base_updater.Updater( 45 # This is absolute so we get the fast path out of the path canonicalization 46 # that would otherwise require us to define ANDROID_BUILD_TOP or run from a 47 # temp repo tree. 48 Path("/"), 49 identifier, 50 "", 51 ) 52 self.assertEqual(updater.current_version, "old version") 53 54 55if __name__ == "__main__": 56 unittest.main(verbosity=2) 57