1# Copyright 2022 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"""Unit tests for run_all_tests script."""
15
16import itertools
17import os
18import unittest
19
20import run_all_tests
21
22
23class RunAllUnitTests(unittest.TestCase):
24  """Unit tests to verify run_all_tests tool."""
25
26  def _scene_folders_exist(self, scene_folders):
27    """Asserts all scene_folders exist in tests directory."""
28    for scene_folder in scene_folders:
29      scene_path = os.path.join(os.environ['CAMERA_ITS_TOP'],
30                                'tests', scene_folder)
31      self.assertTrue(os.path.exists(scene_path),
32                      msg=f'{scene_path} does not exist!')
33
34  def test_sub_camera_tests(self):
35    """Ensures SUB_CAMERA_TESTS matches test files in tests directory."""
36    for scene_folder in run_all_tests.SUB_CAMERA_TESTS:
37      for test in run_all_tests.SUB_CAMERA_TESTS[scene_folder]:
38        test_path = os.path.join(os.environ['CAMERA_ITS_TOP'],
39                                 'tests', scene_folder, f'{test}.py')
40        self.assertTrue(os.path.exists(test_path),
41                        msg=f'{test_path} does not exist!')
42
43  def test_all_scenes(self):
44    """Ensures _ALL_SCENES list matches scene folders in test directory."""
45    self._scene_folders_exist(run_all_tests._ALL_SCENES)
46
47  def test_tablet_scenes(self):
48    """Ensures _TABLET_SCENES list matches scene folders in test directory."""
49    self._scene_folders_exist(run_all_tests._TABLET_SCENES)
50
51  def test_scene_req(self):
52    """Ensures _SCENE_REQ scenes match scene folders in test directory."""
53    self._scene_folders_exist(run_all_tests._SCENE_REQ.keys())
54
55  def test_grouped_scenes(self):
56    """Ensures _GROUPED_SCENES scenes match scene folders in test directory."""
57    # flatten list of scene folder lists stored as values of a dictionary
58    scene_folders = list(itertools.chain.from_iterable(
59        run_all_tests._GROUPED_SCENES.values()))
60    self._scene_folders_exist(scene_folders)
61
62if __name__ == '__main__':
63  unittest.main()
64