예제 #1
0
 def test_can_detect_binary_source_code(self):
     binary_path = _test_path('some_django', 'mo')
     with open(binary_path, 'wb') as binary_file:
         binary_file.write(b'hello\0world!')
     source_analysis = analysis.source_analysis(binary_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.state, analysis.SourceState.binary.name)
     self.assertEqual(source_analysis.code, 0)
예제 #2
0
 def test_can_detect_silent_dos_batch_remarks(self):
     test_bat_path = _test_path("test_can_detect_silent_dos_batch_remarks", "bat")
     _write_test_file(test_bat_path, ["rem normal comment", "@rem silent comment", "echo some code"])
     source_analysis = analysis.source_analysis(test_bat_path, "test", encoding="utf-8")
     assert source_analysis.language == "Batchfile"
     assert source_analysis.code == 1
     assert source_analysis.documentation == 2
예제 #3
0
 def test_can_analyze_webfocus(self):
     test_fex_path = _test_path("test_can_analyze_webfocus", "fex")
     _write_test_file(test_fex_path, ["-* comment", "-type some text", "table file some print * end;"])
     source_analysis = analysis.source_analysis(test_fex_path, "test", encoding="utf-8")
     assert source_analysis.language == "WebFOCUS"
     assert source_analysis.code == 2
     assert source_analysis.documentation == 1
예제 #4
0
 def test_can_detect_binary_source_code(self):
     binary_path = _test_path("some_django", "mo")
     with open(binary_path, "wb") as binary_file:
         binary_file.write(b"hello\0world!")
     source_analysis = analysis.source_analysis(binary_path, "test", encoding="utf-8")
     assert source_analysis.state == analysis.SourceState.binary.name
     assert source_analysis.code == 0
예제 #5
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)
예제 #6
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)
예제 #7
0
 def test_can_analyze_project_text_files(self):
     project_root_folder = os.path.dirname(_TESTS_FOLDER)
     for text_path in glob.glob(os.path.join(project_root_folder, "*.txt")):
         source_analysis = analysis.source_analysis(text_path, "test")
         assert source_analysis.state == analysis.SourceState.analyzed.name
         assert source_analysis.documentation > 0
         if "requirements.txt" not in text_path:
             assert source_analysis.empty > 0
예제 #8
0
 def test_can_analyze_encoding_error(self):
     test_path = _test_path('encoding_error', 'py')
     with open(test_path, 'w', encoding='cp1252') as test_file:
         test_file.write('print("\N{EURO SIGN}")')
     source_analysis = analysis.source_analysis(test_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.language, '__error__')
     self.assertEqual(source_analysis.state, analysis.SourceState.error.name)
     self.assertRegex(str(source_analysis.state_info), '.*0x80')
예제 #9
0
 def test_can_analyze_encoding_error(self):
     test_path = _test_path("encoding_error", "py")
     with open(test_path, "w", encoding="cp1252") as test_file:
         test_file.write('print("\N{EURO SIGN}")')
     source_analysis = analysis.source_analysis(test_path, "test", encoding="utf-8")
     assert source_analysis.language == "__error__"
     assert source_analysis.state == analysis.SourceState.error.name
     assert "0x80" in str(source_analysis.state_info)
예제 #10
0
 def test_can_analyze_encoding_error(self):
     test_path = _test_path('encoding_error', 'py')
     with open(test_path, 'w', encoding='cp1252') as test_file:
         test_file.write('print("\N{EURO SIGN}")')
     source_analysis = analysis.source_analysis(test_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.language, '__error__')
     self.assertEqual(source_analysis.state, analysis.SourceState.error.name)
     self.assertRegex(str(source_analysis.state_info), '.*0x80')
예제 #11
0
 def test_can_analyze_project_text_files(self):
     project_root_folder = os.path.dirname(_TESTS_FOLDER)
     for text_path in glob.glob(os.path.join(project_root_folder, '*.txt')):
         source_analysis = analysis.source_analysis(text_path, 'test')
         self.assertEqual(source_analysis.state, analysis.SourceState.analyzed.name, text_path)
         self.assertGreater(source_analysis.documentation, 0, text_path)
         if 'requirements.txt' not in text_path:
             self.assertGreater(source_analysis.empty, 0, text_path)
예제 #12
0
 def test_can_analyze_project_text_files(self):
     project_root_folder = os.path.dirname(_TESTS_FOLDER)
     for text_path in glob.glob(os.path.join(project_root_folder, '*.txt')):
         source_analysis = analysis.source_analysis(text_path, 'test')
         self.assertEqual(source_analysis.state, analysis.SourceState.analyzed.name, text_path)
         self.assertGreater(source_analysis.documentation, 0, text_path)
         if 'requirements.txt' not in text_path:
             self.assertGreater(source_analysis.empty, 0, text_path)
예제 #13
0
 def test_can_analyze_encoding_error(self):
     test_path = AnalysisTest._test_path('encoding_error', '.py')
     with open(test_path, 'w', encoding='cp1252') as test_file:
         test_file.write('print("\N{EURO SIGN}")')
     source_analysis = analysis.source_analysis(test_path,
                                                'test',
                                                encoding='utf-8')
     self.assertEqual(source_analysis.language, 'error')
예제 #14
0
 def test_can_detect_empty_source_code(self):
     empty_py_path = _test_path("empty", "py")
     _write_test_file(empty_py_path)
     source_analysis = analysis.source_analysis(empty_py_path,
                                                "test",
                                                encoding="utf-8")
     assert source_analysis.state == analysis.SourceState.empty.name
     assert source_analysis.code == 0
예제 #15
0
 def test_can_analyze_oracle_sql(self):
     test_oracle_sql_path = _test_path("test_can_analyze_oracle_sql", "pls")
     _write_test_file(
         test_oracle_sql_path, ["-- Oracle SQL example using an obscure suffix.", "select *", "from some_table;"]
     )
     source_analysis = analysis.source_analysis(test_oracle_sql_path, "test", encoding="utf-8")
     assert source_analysis.language.lower().endswith("sql")
     assert source_analysis.code == 2
     assert source_analysis.documentation == 1
예제 #16
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")
     )
     assert source_analysis.state == analysis.SourceState.generated.name
예제 #17
0
 def test_fails_on_unknown_magic_encoding_comment(self):
     test_path = _test_path('unknown_magic_encoding_comment', 'py')
     with open(test_path, 'w', encoding='utf-8') as test_file:
         test_file.write('# -*- coding: no_such_encoding -*-')
         test_file.write('print("hello")')
     no_such_encoding = analysis.encoding_for(test_path)
     self.assertEqual(no_such_encoding, 'no_such_encoding')
     source_analysis = analysis.source_analysis(test_path, 'test', encoding=no_such_encoding)
     self.assertEqual(source_analysis.language, '__error__')
     self.assertEqual(source_analysis.state, analysis.SourceState.error.name)
     self.assertRegex(str(source_analysis.state_info), '.*unknown encoding')
예제 #18
0
 def test_can_analyze_oracle_sql(self):
     test_oracle_sql_path = _test_path('test_can_analyze_oracle_sql', 'pls')
     _write_test_file(test_oracle_sql_path, [
         '-- Oracle SQL example using an obscure suffix.',
         'select *',
         'from some_table;',
     ])
     source_analysis = analysis.source_analysis(test_oracle_sql_path, 'test', encoding='utf-8')
     self.assertRegex(source_analysis.language.lower(), '.*sql')
     self.assertEqual(source_analysis.code, 2)
     self.assertEqual(source_analysis.documentation, 1)
예제 #19
0
 def test_fails_on_unknown_magic_encoding_comment(self):
     test_path = _test_path("unknown_magic_encoding_comment", "py")
     with open(test_path, "w", encoding="utf-8") as test_file:
         test_file.write("# -*- coding: no_such_encoding -*-")
         test_file.write('print("hello")')
     no_such_encoding = analysis.encoding_for(test_path)
     assert no_such_encoding == "no_such_encoding"
     source_analysis = analysis.source_analysis(test_path, "test", encoding=no_such_encoding)
     assert source_analysis.language == "__error__"
     assert source_analysis.state == analysis.SourceState.error.name
     assert "unknown encoding" in str(source_analysis.state_info)
예제 #20
0
 def test_fails_on_unknown_magic_encoding_comment(self):
     test_path = _test_path('unknown_magic_encoding_comment', 'py')
     with open(test_path, 'w', encoding='utf-8') as test_file:
         test_file.write('# -*- coding: no_such_encoding -*-')
         test_file.write('print("hello")')
     no_such_encoding = analysis.encoding_for(test_path)
     self.assertEqual(no_such_encoding, 'no_such_encoding')
     source_analysis = analysis.source_analysis(test_path, 'test', encoding=no_such_encoding)
     self.assertEqual(source_analysis.language, '__error__')
     self.assertEqual(source_analysis.state, analysis.SourceState.error.name)
     self.assertRegex(str(source_analysis.state_info), '.*unknown encoding')
예제 #21
0
 def test_can_detect_silent_dos_batch_remarks(self):
     test_bat_path = _test_path('test_can_detect_silent_dos_batch_remarks', 'bat')
     _write_test_file(test_bat_path, [
         'rem normal comment',
         '@rem silent comment',
         'echo some code'
     ])
     source_analysis = analysis.source_analysis(test_bat_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.language, 'Batchfile')
     self.assertEqual(source_analysis.code, 1)
     self.assertEqual(source_analysis.documentation, 2)
예제 #22
0
 def test_can_analyze_webfocus(self):
     test_fex_path = _test_path('test_can_analyze_webfocus', 'fex')
     _write_test_file(test_fex_path, [
         '-* comment',
         '-type some text',
         'table file some print * end;',
     ])
     source_analysis = analysis.source_analysis(test_fex_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.language, 'WebFOCUS')
     self.assertEqual(source_analysis.code, 2)
     self.assertEqual(source_analysis.documentation, 1)
예제 #23
0
 def test_can_analyze_webfocus(self):
     test_fex_path = _test_path('test_can_analyze_webfocus', 'fex')
     _write_test_file(test_fex_path, [
         '-* comment',
         '-type some text',
         'table file some print * end;',
     ])
     source_analysis = analysis.source_analysis(test_fex_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.language, 'WebFOCUS')
     self.assertEqual(source_analysis.code, 2)
     self.assertEqual(source_analysis.documentation, 1)
예제 #24
0
 def test_can_detect_silent_dos_batch_remarks(self):
     test_bat_path = _test_path('test_can_detect_silent_dos_batch_remarks', 'bat')
     _write_test_file(test_bat_path, [
         'rem normal comment',
         '@rem silent comment',
         'echo some code'
     ])
     source_analysis = analysis.source_analysis(test_bat_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.language, 'Batchfile')
     self.assertEqual(source_analysis.code, 1)
     self.assertEqual(source_analysis.documentation, 2)
예제 #25
0
def test_can_match_deprecated_functions():
    source_path = __file__
    group = "some"
    assert str(analysis.source_analysis(source_path, group)) == str(
        analysis.SourceAnalysis.from_file(source_path, group))

    missing_path = "missing.py"
    reason = "missing"
    assert str(
        analysis.pseudo_source_analysis(
            missing_path, group, analysis.SourceState.error, reason)) == str(
                analysis.SourceAnalysis.from_state(missing_path, group,
                                                   analysis.SourceState.error,
                                                   reason))
예제 #26
0
 def test_can_detect_empty_source_code(self):
     empty_py_path = _test_path('empty', 'py')
     _write_test_file(empty_py_path)
     source_analysis = analysis.source_analysis(empty_py_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.state, analysis.SourceState.empty.name)
     self.assertEqual(source_analysis.code, 0)
예제 #27
0
 def test_can_detect_empty_source_code(self):
     empty_py_path = _test_path('empty', 'py')
     _write_test_file(empty_py_path)
     source_analysis = analysis.source_analysis(empty_py_path, 'test', encoding='utf-8')
     self.assertEqual(source_analysis.state, analysis.SourceState.empty.name)
     self.assertEqual(source_analysis.code, 0)