xref: /aosp_15_r20/tools/asuite/atest/banner_unittest.py (revision c2e18aaa1096c836b086f94603d04f4eb9cf37f5)
1*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2024, The Android Open Source Project
2*c2e18aaaSAndroid Build Coastguard Worker#
3*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*c2e18aaaSAndroid Build Coastguard Worker#
7*c2e18aaaSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
8*c2e18aaaSAndroid Build Coastguard Worker#
9*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License.
14*c2e18aaaSAndroid Build Coastguard Worker
15*c2e18aaaSAndroid Build Coastguard Worker"""Unit tests for banner."""
16*c2e18aaaSAndroid Build Coastguard Worker
17*c2e18aaaSAndroid Build Coastguard Workerfrom pathlib import Path
18*c2e18aaaSAndroid Build Coastguard Workerfrom pyfakefs import fake_filesystem_unittest
19*c2e18aaaSAndroid Build Coastguard Worker
20*c2e18aaaSAndroid Build Coastguard Workerfrom atest import banner
21*c2e18aaaSAndroid Build Coastguard Worker
22*c2e18aaaSAndroid Build Coastguard Worker
23*c2e18aaaSAndroid Build Coastguard Workerclass BannerPrinterTest(fake_filesystem_unittest.TestCase):
24*c2e18aaaSAndroid Build Coastguard Worker  """Tests for BannerPrinter."""
25*c2e18aaaSAndroid Build Coastguard Worker
26*c2e18aaaSAndroid Build Coastguard Worker  def setUp(self):
27*c2e18aaaSAndroid Build Coastguard Worker    self.setUpPyfakefs()
28*c2e18aaaSAndroid Build Coastguard Worker    self.config_dir = Path("/config")
29*c2e18aaaSAndroid Build Coastguard Worker
30*c2e18aaaSAndroid Build Coastguard Worker  def test_print_already_printed_today_does_not_print(self):
31*c2e18aaaSAndroid Build Coastguard Worker    printed_banners = []
32*c2e18aaaSAndroid Build Coastguard Worker    print_func = lambda m: printed_banners.append(m)
33*c2e18aaaSAndroid Build Coastguard Worker    date_supplier = lambda : "2024-04-16"
34*c2e18aaaSAndroid Build Coastguard Worker    printer_1 = banner.BannerPrinter(self.config_dir)
35*c2e18aaaSAndroid Build Coastguard Worker    printer_1.register("banner message1")
36*c2e18aaaSAndroid Build Coastguard Worker    printer_1.print(print_func=print_func, date_supplier=date_supplier)
37*c2e18aaaSAndroid Build Coastguard Worker    printer_2 = banner.BannerPrinter(self.config_dir)
38*c2e18aaaSAndroid Build Coastguard Worker    printer_2.register("banner message2")
39*c2e18aaaSAndroid Build Coastguard Worker
40*c2e18aaaSAndroid Build Coastguard Worker    printer_2.print(print_func=print_func, date_supplier=date_supplier)
41*c2e18aaaSAndroid Build Coastguard Worker
42*c2e18aaaSAndroid Build Coastguard Worker    self.assertCountEqual(printed_banners, ["banner message1"])
43