diff --git a/codebasin/source.py b/codebasin/source.py index 53dae02..2084704 100644 --- a/codebasin/source.py +++ b/codebasin/source.py @@ -3,10 +3,9 @@ import os from pathlib import Path -from typing import Union -def is_source_file(filename: Union[str, os.PathLike]) -> bool: +def is_source_file(filename: str | os.PathLike) -> bool: """ Parameters ---------- diff --git a/tests/comments/test_comments.py b/tests/comments/test_comments.py index f63d784..f6c8021 100644 --- a/tests/comments/test_comments.py +++ b/tests/comments/test_comments.py @@ -1,10 +1,10 @@ # Copyright (C) 2019 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause -import unittest -import logging import os -from codebasin import preprocessor, file_parser +import unittest + +from codebasin import file_parser class TestExampleFortranFile(unittest.TestCase): @@ -27,11 +27,13 @@ class TestExampleCFile(unittest.TestCase): def test_c_comments(self): rootdir = "./tests/comments/" - parser = file_parser.FileParser(os.path.join(rootdir, "continuation.cpp")) + parser = file_parser.FileParser( + os.path.join(rootdir, "continuation.cpp"), + ) tree = parser.parse_file() self.assertEqual(tree.root.total_sloc, 25) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/compilers/test_compilers.py b/tests/compilers/test_compilers.py index 02f6abd..b60c8ed 100644 --- a/tests/compilers/test_compilers.py +++ b/tests/compilers/test_compilers.py @@ -1,10 +1,12 @@ # Copyright (C) 2019-2024 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause -import unittest import logging +import unittest + from codebasin import config + class TestCompilers(unittest.TestCase): """ Test that a subset of common compilers and their arguments are recognized @@ -16,17 +18,13 @@ def setUp(self): def test_clang(self): """compilers/clang""" - args = [ - "clang", - "-fsycl-is-device", - "test.cpp" - ] + args = ["clang", "-fsycl-is-device", "test.cpp"] compiler = config.recognize_compiler(args) self.assertTrue(type(compiler) is config.ClangCompiler) passes = compiler.get_passes() - self.assertEqual(passes, set(["default"])) + self.assertEqual(passes, {"default"}) self.assertTrue(compiler.has_implicit_behavior("default")) defines = compiler.get_defines("default") @@ -34,23 +32,15 @@ def test_clang(self): def test_intel_sycl(self): """compilers/intel_sycl""" - args = [ - "icpx", - "-fsycl", - "test.cpp" - ] + args = ["icpx", "-fsycl", "test.cpp"] compiler = config.recognize_compiler(args) self.assertTrue(type(compiler) is config.IntelCompiler) passes = compiler.get_passes() - self.assertEqual(passes, set(["default", "spir64"])) + self.assertEqual(passes, {"default", "spir64"}) - expected = [ - "__SYCL_DEVICE_ONLY__", - "__SPIR__", - "__SPIRV__" - ] + expected = ["__SYCL_DEVICE_ONLY__", "__SPIR__", "__SPIRV__"] self.assertTrue(compiler.has_implicit_behavior("spir64")) defines = compiler.get_defines("spir64") self.assertEqual(defines, expected) @@ -62,24 +52,20 @@ def test_intel_targets(self): "-fsycl", "-fsycl-targets=spir64,x86_64", "-fopenmp", - "test.cpp" + "test.cpp", ] compiler = config.recognize_compiler(args) self.assertTrue(type(compiler) is config.IntelCompiler) passes = compiler.get_passes() - self.assertEqual(passes, set(["default", "spir64", "x86_64"])) + self.assertEqual(passes, {"default", "spir64", "x86_64"}) self.assertTrue(compiler.has_implicit_behavior("default")) defines = compiler.get_defines("default") self.assertEqual(defines, ["_OPENMP"]) - expected = [ - "__SYCL_DEVICE_ONLY__", - "__SPIR__", - "__SPIRV__" - ] + expected = ["__SYCL_DEVICE_ONLY__", "__SPIR__", "__SPIRV__"] self.assertTrue(compiler.has_implicit_behavior("spir64")) defines = compiler.get_defines("spir64") self.assertEqual(defines, expected) @@ -93,19 +79,16 @@ def test_nvcc(self): "nvcc", "--gpu-architecture=compute_50", "--gpu-code=compute_50,sm_50,sm_52", - "test.cpp" + "test.cpp", ] compiler = config.recognize_compiler(args) self.assertTrue(type(compiler) is config.NvccCompiler) passes = compiler.get_passes() - self.assertEqual(passes, set(["default", "50", "52"])) + self.assertEqual(passes, {"default", "50", "52"}) - defaults = [ - "__NVCC__", - "__CUDACC__" - ] + defaults = ["__NVCC__", "__CUDACC__"] self.assertTrue(compiler.has_implicit_behavior("default")) defines = compiler.get_defines("default") self.assertEqual(defines, defaults) @@ -118,5 +101,6 @@ def test_nvcc(self): defines = compiler.get_defines("52") self.assertEqual(defines, defaults + ["__CUDA_ARCH__=520"]) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/tests/failure/test_bignum.py b/tests/failure/test_bignum.py index 3c7bb71..37dfe64 100644 --- a/tests/failure/test_bignum.py +++ b/tests/failure/test_bignum.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause import unittest + from codebasin import preprocessor @@ -13,13 +14,17 @@ class TestBigNum(unittest.TestCase): def test_oversized_constant(self): """oversized constant""" with self.assertRaises(OverflowError): - tokens = preprocessor.Lexer("10000000000000000000000000000000000000").tokenize() + tokens = preprocessor.Lexer( + "10000000000000000000000000000000000000", + ).tokenize() preprocessor.ExpressionEvaluator(tokens).evaluate() def test_overflow(self): """integer overflow""" with self.assertRaises(OverflowError): - tokens = preprocessor.Lexer("0xFFFFFFFFFFFFFFFF * 0xFFFFFFFFFFFFFFFF").tokenize() + tokens = preprocessor.Lexer( + "0xFFFFFFFFFFFFFFFF * 0xFFFFFFFFFFFFFFFF", + ).tokenize() preprocessor.ExpressionEvaluator(tokens).evaluate() def test_power(self): diff --git a/tests/lexer/test_lexer.py b/tests/lexer/test_lexer.py index 4a1e7ef..b890368 100644 --- a/tests/lexer/test_lexer.py +++ b/tests/lexer/test_lexer.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause import unittest + from codebasin import preprocessor @@ -18,15 +19,25 @@ def test_character(self): def test_numerical(self): """numbers""" - numbers = ["123", "123ul", "123.4", "123.4e+05", ".123", "0xFF", "0b10"] + numbers = [ + "123", + "123ul", + "123.4", + "123.4e+05", + ".123", + "0xFF", + "0b10", + ] for number in numbers: tokens = preprocessor.Lexer(number).tokenize() self.assertTrue(len(tokens) == 1) - self.assertTrue(isinstance(tokens[0], preprocessor.NumericalConstant)) + self.assertTrue( + isinstance(tokens[0], preprocessor.NumericalConstant), + ) def test_string(self): """strings""" - tokens = preprocessor.Lexer("\"this is a string constant\"").tokenize() + tokens = preprocessor.Lexer('"this is a string constant"').tokenize() self.assertTrue(len(tokens) == 1) self.assertTrue(isinstance(tokens[0], preprocessor.StringConstant)) @@ -34,12 +45,30 @@ def test_identifier(self): """identifiers""" tokens = preprocessor.Lexer("this is a string of words").tokenize() self.assertTrue(len(tokens) == 6) - self.assertTrue(all([isinstance(t, preprocessor.Identifier) for t in tokens])) + self.assertTrue( + all([isinstance(t, preprocessor.Identifier) for t in tokens]), + ) def test_operator(self): """operators""" - operators = ["||", "&&", ">>", "<<", "!=", ">=", "<=", "==", "##"] + \ - ["-", "+", "!", "*", "/", "|", "&", "^", "<", ">", "?", ":", "~", "#", "=", "%"] + operators = ["||", "&&", ">>", "<<", "!=", ">=", "<=", "==", "##"] + [ + "-", + "+", + "!", + "*", + "/", + "|", + "&", + "^", + "<", + ">", + "?", + ":", + "~", + "#", + "=", + "%", + ] for op in operators: tokens = preprocessor.Lexer(op).tokenize() self.assertTrue(len(tokens) == 1) @@ -48,7 +77,20 @@ def test_operator(self): def test_puncuator(self): """punctuators""" - punctuators = ["(", ")", "{", "}", "[", "]", ",", ".", ";", "'", "\"", "\\"] + punctuators = [ + "(", + ")", + "{", + "}", + "[", + "]", + ",", + ".", + ";", + "'", + '"', + "\\", + ] for punc in punctuators: tokens = preprocessor.Lexer(punc).tokenize() self.assertTrue(len(tokens) == 1) @@ -70,7 +112,9 @@ def test_expression(self): self.assertTrue(isinstance(tokens[8], preprocessor.Operator)) self.assertTrue(isinstance(tokens[9], preprocessor.CharacterConstant)) - tokens = preprocessor.Lexer("a > b ? \"true_string\" : \"false_string\"").tokenize() + tokens = preprocessor.Lexer( + 'a > b ? "true_string" : "false_string"', + ).tokenize() self.assertTrue(len(tokens) == 7) self.assertTrue(isinstance(tokens[0], preprocessor.Identifier)) self.assertTrue(isinstance(tokens[1], preprocessor.Operator)) @@ -81,5 +125,5 @@ def test_expression(self): self.assertTrue(isinstance(tokens[6], preprocessor.StringConstant)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/parsers/test_directive_parser.py b/tests/parsers/test_directive_parser.py index c389735..f13c099 100644 --- a/tests/parsers/test_directive_parser.py +++ b/tests/parsers/test_directive_parser.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause import unittest + from codebasin import preprocessor @@ -68,13 +69,17 @@ def test_undef(self): def test_include(self): """include""" - tokens = preprocessor.Lexer("#include ").tokenize() + tokens = preprocessor.Lexer( + "#include ", + ).tokenize() node = preprocessor.DirectiveParser(tokens).parse() self.assertTrue(isinstance(node, preprocessor.IncludeNode)) self.assertTrue(isinstance(node.value, preprocessor.IncludePath)) self.assertTrue(node.value.system) - tokens = preprocessor.Lexer("#include \"path/to/local/header\"").tokenize() + tokens = preprocessor.Lexer( + '#include "path/to/local/header"', + ).tokenize() node = preprocessor.DirectiveParser(tokens).parse() self.assertTrue(isinstance(node, preprocessor.IncludeNode)) self.assertTrue(isinstance(node.value, preprocessor.IncludePath)) @@ -143,8 +148,10 @@ def test_unsupported(self): for directive in ["#line", "#warning", "#error"]: tokens = preprocessor.Lexer(directive).tokenize() node = preprocessor.DirectiveParser(tokens).parse() - self.assertTrue(isinstance(node, preprocessor.UnrecognizedDirectiveNode)) + self.assertTrue( + isinstance(node, preprocessor.UnrecognizedDirectiveNode), + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/safe_write/test_safe_write.py b/tests/safe_write/test_safe_write.py index dfb1a5b..604e04e 100644 --- a/tests/safe_write/test_safe_write.py +++ b/tests/safe_write/test_safe_write.py @@ -1,10 +1,10 @@ # Copyright (C) 2019 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause -import unittest -import tempfile -import shutil import os +import shutil +import tempfile +import unittest from codebasin import util @@ -76,5 +76,5 @@ def test_create(self): self.assertEqual(st.st_mode & 0o111, 0) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/valid_path/test_valid_path.py b/tests/valid_path/test_valid_path.py index 1a55dd1..c997a3b 100644 --- a/tests/valid_path/test_valid_path.py +++ b/tests/valid_path/test_valid_path.py @@ -29,5 +29,5 @@ def test_line_feed(self): self.assertFalse(util.valid_path("/invalid/\n/path/")) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main()