1 # Copyright 2020 The Pigweed Authors
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
7 # https://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
14 """Tests for file_operations module."""
20 from pathlib import Path
21 from parameterized import parameterized # type: ignore
23 from pw_arduino_build import file_operations
40 def create_files(root_dir, file_names):
41 for file_name in file_names:
42 folder_path = Path(root_dir) / Path(os.path.dirname(file_name))
43 folder_path.mkdir(parents=True, exist_ok=True)
44 file_path = Path(root_dir) / Path(file_name)
45 file_path.touch(exist_ok=True)
48 class TestFileOperations(unittest.TestCase):
49 """Tests to ensure arduino core library source files can be found."""
51 self.test_dir = tempfile.mkdtemp()
54 shutil.rmtree(self.test_dir)
56 @parameterized.expand([
58 "sources recursive", file_set(), ["**/*.ino", "**/*.h", "**/*.cpp"],
61 os.path.join("core", "pwm", "pulse.h"),
62 os.path.join("libraries", "b.cpp"),
63 os.path.join("libraries", "c.h"),
67 "directories recursive", file_set(), ["**"],
70 os.path.join("core", "pwm"),
75 "directories one level deep", file_set(), ["*"],
82 "items one level deep", file_set(), ["*"],
90 def test_find_files(self, test_case, base_fileset, patterns,
92 """Test find_files on source files and directories."""
93 create_files(self.test_dir, base_fileset)
94 result = file_operations.find_files(self.test_dir,
96 directories_only=("directories"
98 self.assertSequenceEqual(expected_results, result)
101 if __name__ == '__main__':