1# Copyright 2024, The Android Open Source Project 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 15"""Unit tests for banner.""" 16 17from pathlib import Path 18from pyfakefs import fake_filesystem_unittest 19 20from atest import banner 21 22 23class BannerPrinterTest(fake_filesystem_unittest.TestCase): 24 """Tests for BannerPrinter.""" 25 26 def setUp(self): 27 self.setUpPyfakefs() 28 self.config_dir = Path("/config") 29 30 def test_print_already_printed_today_does_not_print(self): 31 printed_banners = [] 32 print_func = lambda m: printed_banners.append(m) 33 date_supplier = lambda : "2024-04-16" 34 printer_1 = banner.BannerPrinter(self.config_dir) 35 printer_1.register("banner message1") 36 printer_1.print(print_func=print_func, date_supplier=date_supplier) 37 printer_2 = banner.BannerPrinter(self.config_dir) 38 printer_2.register("banner message2") 39 40 printer_2.print(print_func=print_func, date_supplier=date_supplier) 41 42 self.assertCountEqual(printed_banners, ["banner message1"]) 43