Skip to content

Commit 667caf7

Browse files
committed
Add tests for is_source_file function
- Test that strings are handled correctly. - Test that Paths are handled correctly. - Test for TypeError if argument is not a string or Path. Signed-off-by: John Pennycook <john.pennycook@intel.com>
1 parent 27c953a commit 667caf7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/source/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (C) 2019-2024 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause

tests/source/test_source.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2019-2024 Intel Corporation
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
import unittest
5+
from pathlib import Path
6+
7+
import codebasin.source as source
8+
9+
10+
class TestSource(unittest.TestCase):
11+
"""
12+
Test functionality in the source module.
13+
"""
14+
15+
def test_is_source_file_string(self):
16+
"""Check source file identification for string filenames"""
17+
self.assertTrue(source.is_source_file("file.cpp"))
18+
self.assertTrue(source.is_source_file("/path/to/file.cpp"))
19+
self.assertFalse(source.is_source_file("file.o"))
20+
self.assertFalse(source.is_source_file("/path/to/file.o"))
21+
22+
def test_is_source_file_path(self):
23+
"""Check source file identification for Path filenames"""
24+
self.assertTrue(source.is_source_file(Path("file.cpp")))
25+
self.assertTrue(source.is_source_file(Path("/path/to/file.cpp")))
26+
self.assertFalse(source.is_source_file(Path("file.o")))
27+
self.assertFalse(source.is_source_file(Path("/path/to/file.o")))
28+
29+
def test_is_source_types(self):
30+
"""Check type validation for is_source"""
31+
with self.assertRaises(TypeError):
32+
source.is_source_file(1)
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()

0 commit comments

Comments
 (0)