コード例 #1
0
 def test_can_detect_non_generated_code(self):
     _DEFAULT_GENERATED_REGEXES = common.regexes_from(
         analysis.DEFAULT_GENERATED_PATTERNS_TEXT)
     with open(__file__, "r", encoding="utf-8") as source_file:
         matching_line_number_and_regex = analysis.matching_number_line_and_regex(
             source_file, _DEFAULT_GENERATED_REGEXES)
     assert matching_line_number_and_regex is None
コード例 #2
0
ファイル: test_analysis.py プロジェクト: roskakori/pygount
 def test_can_analyze_generated_code_with_own_pattern(self):
     generated_sql_path = _test_path('generated', 'sql')
     with open(generated_sql_path, 'w', encoding='utf-8') as generated_sql_file:
         generated_sql_file.write('-- Generiert mit Hau-Ruck-Franz-Deutsch.\n')
         generated_sql_file.write('select * from sauerkraut;\n')
     source_analysis = analysis.source_analysis(
         generated_sql_path, 'test', generated_regexes=common.regexes_from('[regex](?i).*generiert'))
     self.assertEqual(source_analysis.state, analysis.SourceState.generated.name)
コード例 #3
0
 def test_can_analyze_generated_code_with_own_pattern(self):
     generated_sql_path = _test_path('generated', 'sql')
     with open(generated_sql_path, 'w', encoding='utf-8') as generated_sql_file:
         generated_sql_file.write('-- Generiert mit Hau-Ruck-Franz-Deutsch.\n')
         generated_sql_file.write('select * from sauerkraut;\n')
     source_analysis = analysis.source_analysis(
         generated_sql_path, 'test', generated_regexes=common.regexes_from('[regex](?i).*generiert'))
     self.assertEqual(source_analysis.state, analysis.SourceState.generated.name)
コード例 #4
0
ファイル: test_analysis.py プロジェクト: pclausen/pygount
 def test_can_analyze_generated_code_with_own_pattern(self):
     generated_sql_path = _test_path("generated", "sql")
     with open(generated_sql_path, "w", encoding="utf-8") as generated_sql_file:
         generated_sql_file.write("-- Generiert mit Hau-Ruck-Franz-Deutsch.\n")
         generated_sql_file.write("select * from sauerkraut;\n")
     source_analysis = analysis.source_analysis(
         generated_sql_path, "test", generated_regexes=common.regexes_from("[regex](?i).*generiert")
     )
     assert source_analysis.state == analysis.SourceState.generated.name
コード例 #5
0
ファイル: test_analysis.py プロジェクト: oarevaloy/pygount
 def test_can_analyze_generated_code_with_own_pattern(self):
     lines = [
         "-- Generiert mit Hau-Ruck-Franz-Deutsch.",
         "select * from sauerkraut;"
     ]
     generated_sql_path = self.create_temp_file("generated.sql", lines)
     source_analysis = analysis.SourceAnalysis.from_file(
         generated_sql_path,
         "test",
         generated_regexes=common.regexes_from("[regex](?i).*generiert"))
     assert source_analysis.state == analysis.SourceState.generated
コード例 #6
0
class GeneratedCodeTest(unittest.TestCase):
    _STANDARD_SOURCE_LINES = """#!/bin/python3
    # Example code for
    # generated source code.
    print("I'm generated!")
    """.split("\n")
    _STANDARD_GENERATED_REGEXES = common.regexes_from(
        common.REGEX_PATTERN_PREFIX + ".*some,.*other,.*generated,.*print")

    def test_can_detect_non_generated_code(self):
        _DEFAULT_GENERATED_REGEXES = common.regexes_from(
            analysis.DEFAULT_GENERATED_PATTERNS_TEXT)
        with open(__file__, "r", encoding="utf-8") as source_file:
            matching_line_number_and_regex = analysis.matching_number_line_and_regex(
                source_file, _DEFAULT_GENERATED_REGEXES)
        assert matching_line_number_and_regex is None

    def test_can_detect_generated_code(self):
        matching_number_line_and_regex = analysis.matching_number_line_and_regex(
            GeneratedCodeTest._STANDARD_SOURCE_LINES,
            GeneratedCodeTest._STANDARD_GENERATED_REGEXES)
        assert matching_number_line_and_regex is not None
        matching_number, matching_line, matching_regex = matching_number_line_and_regex
        assert matching_number == 2
        assert matching_line == GeneratedCodeTest._STANDARD_SOURCE_LINES[2]
        assert matching_regex == GeneratedCodeTest._STANDARD_GENERATED_REGEXES[
            2]

    def test_can_not_detect_generated_code_with_late_comment(self):
        non_matching_number_line_and_regex = analysis.matching_number_line_and_regex(
            GeneratedCodeTest._STANDARD_SOURCE_LINES,
            GeneratedCodeTest._STANDARD_GENERATED_REGEXES, 2)
        assert non_matching_number_line_and_regex is None

    def test_can_analyze_generated_code_with_own_pattern(self):
        generated_sql_path = _test_path("generated", "sql")
        with open(generated_sql_path, "w",
                  encoding="utf-8") as generated_sql_file:
            generated_sql_file.write(
                "-- Generiert mit Hau-Ruck-Franz-Deutsch.\n")
            generated_sql_file.write("select * from sauerkraut;\n")
        source_analysis = analysis.source_analysis(
            generated_sql_path,
            "test",
            generated_regexes=common.regexes_from("[regex](?i).*generiert"))
        assert source_analysis.state == analysis.SourceState.generated.name
コード例 #7
0
class GeneratedCodeTest(unittest.TestCase):
    _STANDARD_SOURCE_LINES = """#!/bin/python3
    # Example code for
    # generated source code.
    print("I'm generated!")
    """.split('\n')
    _STANDARD_GENERATED_REGEXES = common.regexes_from(
        common.REGEX_PATTERN_PREFIX + '.*some,.*other,.*generated,.*print')

    def test_can_detect_non_generated_code(self):
        _DEFAULT_GENERATED_REGEXES = common.regexes_from(analysis.DEFAULT_GENERATED_PATTERNS_TEXT)
        with open(__file__, 'r', encoding='utf-8') as source_file:
            matching_line_number_and_regex = analysis.matching_number_line_and_regex(
                source_file, _DEFAULT_GENERATED_REGEXES)
        self.assertIsNone(matching_line_number_and_regex)

    def test_can_detect_generated_code(self):
        matching_number_line_and_regex = analysis.matching_number_line_and_regex(
            GeneratedCodeTest._STANDARD_SOURCE_LINES,
            GeneratedCodeTest._STANDARD_GENERATED_REGEXES)
        self.assertIsNotNone(matching_number_line_and_regex)
        matching_number, matching_line, matching_regex = matching_number_line_and_regex
        self.assertEqual(matching_number, 2)
        self.assertEqual(matching_line, GeneratedCodeTest._STANDARD_SOURCE_LINES[2])
        self.assertEqual(matching_regex, GeneratedCodeTest._STANDARD_GENERATED_REGEXES[2])

    def test_can_not_detect_generated_code_with_late_comment(self):
        non_matching_number_line_and_regex = analysis.matching_number_line_and_regex(
            GeneratedCodeTest._STANDARD_SOURCE_LINES,
            GeneratedCodeTest._STANDARD_GENERATED_REGEXES,
            2)
        self.assertIsNone(non_matching_number_line_and_regex)

    def test_can_analyze_generated_code_with_own_pattern(self):
        generated_sql_path = _test_path('generated', 'sql')
        with open(generated_sql_path, 'w', encoding='utf-8') as generated_sql_file:
            generated_sql_file.write('-- Generiert mit Hau-Ruck-Franz-Deutsch.\n')
            generated_sql_file.write('select * from sauerkraut;\n')
        source_analysis = analysis.source_analysis(
            generated_sql_path, 'test', generated_regexes=common.regexes_from('[regex](?i).*generiert'))
        self.assertEqual(source_analysis.state, analysis.SourceState.generated.name)
コード例 #8
0
ファイル: test_analysis.py プロジェクト: roskakori/pygount
 def test_can_detect_non_generated_code(self):
     _DEFAULT_GENERATED_REGEXES = common.regexes_from(analysis.DEFAULT_GENERATED_PATTERNS_TEXT)
     with open(__file__, 'r', encoding='utf-8') as source_file:
         matching_line_number_and_regex = analysis.matching_number_line_and_regex(
             source_file, _DEFAULT_GENERATED_REGEXES)
     self.assertIsNone(matching_line_number_and_regex)