diff --git a/nirjas/languages/tests/__init__.py b/nirjas/languages/tests/__init__.py index e69de29..f2c451b 100644 --- a/nirjas/languages/tests/__init__.py +++ b/nirjas/languages/tests/__init__.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +''' +SPDX-License-Identifier: LGPL-2.1 + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Test scripts for Nirjas +''' diff --git a/nirjas/languages/tests/test_c.py b/nirjas/languages/tests/test_c.py index cf00afc..4c15363 100644 --- a/nirjas/languages/tests/test_c.py +++ b/nirjas/languages/tests/test_c.py @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +''' +SPDX-License-Identifier: LGPL-2.1 + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +''' + import unittest import os from nirjas.languages import c @@ -5,28 +25,38 @@ class CTest(unittest.TestCase): + ''' + Test cases for C language. + :ivar testfile: Location of test file + ''' testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.c") def test_output(self): + ''' + Check for the scan correctness. + ''' regex = r'''(?" - self.syntax_start = "/*" - self.syntax_end = '*/' - comment_single = html.readMultiLineDiff(self.testfile, self.start_exclamation, self.end_exclamation) - comment_multiline = html.readMultiLineDiff(self.testfile, self.syntax_start, self.syntax_end) + ''' + Check for the scan correctness. + ''' + start_exclamation = "" + syntax_start = "/*" + syntax_end = '*/' + comment_single = readMultiLineDiff(self.testfile, start_exclamation, + end_exclamation) + comment_multiline = readMultiLineDiff(self.testfile, syntax_start, + syntax_end) self.assertTrue(comment_single) self.assertTrue(comment_multiline) def test_outputFormat(self): - self.start_exclamation = "" - self.syntax_start = "/*" - self.syntax_end = '*/' + ''' + Check for the output format correctness. + ''' + start_exclamation = "" + syntax_start = "/*" + syntax_end = '*/' expected = html.htmlExtractor(self.testfile).get_dict() - comment_single = readMultiLineDiff(self.testfile, self.start_exclamation, self.end_exclamation) - comment_multiline = readMultiLineDiff(self.testfile, self.syntax_start, self.syntax_end) + comment_single = readMultiLineDiff(self.testfile, start_exclamation, + end_exclamation) + comment_multiline = readMultiLineDiff(self.testfile, syntax_start, + syntax_end) file = self.testfile.split("/") output = { "metadata": { @@ -42,22 +77,26 @@ def test_outputFormat(self): } if comment_single: - try: - for idx, i in enumerate(comment_single[0]): - output['multi_line_comment'].append({"start_line": comment_single[0][idx], "end_line": comment_single[1][idx], "comment": comment_single[2][idx]}) - except: - pass + for idx, _ in enumerate(comment_single[0]): + output['multi_line_comment'].append({ + "start_line": comment_single[0][idx], + "end_line": comment_single[1][idx], + "comment": comment_single[2][idx]}) if comment_multiline: - try: - for idx, i in enumerate(comment_multiline[0]): - output['multi_line_comment'].append({"start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx]}) - except: - pass + for idx, _ in enumerate(comment_multiline[0]): + output['multi_line_comment'].append({ + "start_line": comment_multiline[0][idx], + "end_line": comment_multiline[1][idx], + "comment": comment_multiline[2][idx]}) self.assertEqual(output, expected) def test_Source(self): + ''' + Test the source code extraction. + Call the source function and check if new file exists. + ''' name = "source.txt" newfile = html.htmlSource(self.testfile, name) diff --git a/nirjas/languages/tests/test_java.py b/nirjas/languages/tests/test_java.py index 0555f9c..d863456 100644 --- a/nirjas/languages/tests/test_java.py +++ b/nirjas/languages/tests/test_java.py @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +''' +SPDX-License-Identifier: LGPL-2.1 + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +''' + import unittest import os from nirjas.languages import java @@ -5,28 +25,39 @@ class JavaTest(unittest.TestCase): - testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.java") + ''' + Test cases for Java language. + :ivar testfile: Location of test file + ''' + testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), + "TestFiles/textcomment.java") def test_output(self): + ''' + Check for the scan correctness. + ''' regex = r'''(?