def test_spell_check(known_words): source_filenames = [Path(__file__).parents[1] / 'setup.py'] + \ list((Path(__file__).parents[1] / 'colcon_cmake').glob('**/*.py')) + \ list((Path(__file__).parents[1] / 'test').glob('**/*.py')) for source_filename in sorted(source_filenames): print('Spell checking:', source_filename) # check all files report = Report(known_words) spell_check([str(p) for p in source_filenames], base_dicts=[SCSPELL_BUILTIN_DICT], report_only=report, additional_extensions=[('', 'Python')]) unknown_word_count = len(report.unknown_words) assert unknown_word_count == 0, \ 'Found {unknown_word_count} unknown words: '.format_map(locals()) + \ ', '.join(sorted(report.unknown_words)) unused_known_words = set(known_words) - report.found_known_words unused_known_word_count = len(unused_known_words) assert unused_known_word_count == 0, \ '{unused_known_word_count} words in the word list are not used: ' \ .format_map(locals()) + ', '.join(sorted(unused_known_words))
def test_additional_extensions(): source_filenames = [os.path.join( os.path.dirname(__file__), 'fileidmap', 'custom.ext')] result = spell_check(source_filenames, report_only=True) assert result is False result = spell_check( source_filenames, report_only=True, additional_extensions=[('.ext', 'Python')]) assert result is True
def test_additional_extensions(): source_filenames = [ os.path.join(os.path.dirname(__file__), 'fileidmap', 'custom.ext') ] result = spell_check(source_filenames, report_only=True) assert result is False result = spell_check(source_filenames, report_only=True, additional_extensions=[('.ext', 'Python')]) assert result is True
def test_additional_extensions(): source_filenames = [os.path.join( os.path.dirname(__file__), 'fileidmap', 'inputfile.txt')] report = Report(('soem', 'other')) result = spell_check(source_filenames, report_only=report) assert result is False # 'other' was not found in the input assert report.found_known_words == {'soem'} assert report.unknown_words == {'wrods', 'finially'}
def test_additional_extensions(): source_filenames = [ os.path.join(os.path.dirname(__file__), 'fileidmap', 'inputfile.txt') ] report = Report(('soem', 'other')) result = spell_check(source_filenames, report_only=report) assert result is False # 'other' was not found in the input assert report.found_known_words == {'soem'} assert report.unknown_words == {'wrods', 'finially'}
def __init__( self, auth, base_url, project_key, repo_slug, commit_id, key, title, description, files_to_check, dictionaries=None, force_pass=False, ): # pylint: disable=too-many-locals results = StringIO() if dictionaries is None: dictionaries = [] with redirect_stderr(results): return_code = spell_check(files_to_check, report_only=True, base_dicts=dictionaries) annotations_string = results.getvalue().strip() if return_code: result = "PASS" else: result = "FAIL" super().__init__( auth, base_url, project_key, repo_slug, commit_id, key, title, description, result, annotations_string=annotations_string, force_pass=force_pass, )
def main(): parser = argparse.ArgumentParser(description=__doc__, prog='scspell') dict_group = parser.add_argument_group("dictionary file management") spell_group = parser.add_argument_group("spell-check control") test_group = parser.add_argument_group("testing options") spell_group.add_argument( '--report-only', dest='report', action='store_true', help='non-interactive report of spelling errors') spell_group.add_argument( '--no-c-escapes', dest='c_escapes', action='store_false', default=True, help="treat \\label as label, for e.g. LaTeX") dict_group.add_argument( '--override-dictionary', dest='override_filename', help='set location of dictionary to FILE, for current session only', metavar='FILE', action='store') dict_group.add_argument( '--set-dictionary', dest='dictionary', help='permanently set location of dictionary to FILE', metavar='FILE', action='store') dict_group.add_argument( '--export-dictionary', dest='export_filename', help='export current dictionary to FILE', metavar='FILE', action='store') dict_group.add_argument( '--base-dict', dest='base_dicts', action='append', default=[], metavar='BASE_DICT', help="Match words from BASE_DICT, but don't modify it.") dict_group.add_argument( '--use-builtin-base-dict', dest='base_dicts', action='append_const', const=scspell.SCSPELL_BUILTIN_DICT, help="Use scspell's default wordlist as a base dictionary ({0})" .format(scspell.SCSPELL_BUILTIN_DICT)) dict_group.add_argument( '--filter-out-base-dicts', action='store_true', help='Remove from the dictionary file ' 'all the words from the base dicts') dict_group.add_argument( '--relative-to', dest='relative_to', help='use file paths relative to here in file ID map. ' 'This is required to enable use of the file ID map', action='store') dict_group.add_argument( '-i', '--gen-id', dest='gen_id', action='store_true', help='generate a unique file-id string') dict_group.add_argument( '--merge-file-ids', nargs=2, metavar=('FROM_ID', 'TO_ID'), help='merge these two file IDs, keeping TO_ID and discarding FROM_ID; ' 'combine their word lists in the dictionary, and the filenames ' 'associated with them in the file ID map; TO_ID and FROM_ID may ' 'be given as file IDs, or as filenames in which case the file ' 'IDs corresponding to those files are operated on; does NOT look ' 'for or consider any file IDs embedded in to-be-spell-checked ' 'files; if your filenames look like file IDs, do it by hand') dict_group.add_argument( '--rename-file', nargs=2, metavar=('FROM_FILE', 'TO_FILE'), help='inform scspell that FROM_FILE has been renamed TO_FILE; ' 'if an entry in the file ID mapping references FROM_FILE, it ' 'will be modified to reference TO_FILE instead') dict_group.add_argument( '--delete-files', action='store_true', default=False, help='inform scspell that the listed files have been deleted; all ' 'file ID mappings for the files will be removed; if all uses of ' 'that file ID have been removed, the corresponding file-private ' 'dictionary will be removed; this will not spell check the ' 'files') # Testing option to allow scspell to read stdin from a non-tty test_group.add_argument( '--test-input', action='store_true', default=False, help=argparse.SUPPRESS) parser.add_argument( '-D', '--debug', dest='debug', action='store_true', help='print extra debugging information') parser.add_argument( '--version', action='version', version='%(prog)s ' + scspell.__version__) parser.add_argument( 'files', nargs='*', help='files to check') args = parser.parse_args() if args.debug: scspell.set_verbosity(scspell.VERBOSITY_MAX) if args.gen_id: print('scspell-id: %s' % scspell.get_new_file_id()) elif args.dictionary is not None: scspell.set_dictionary(args.dictionary) elif args.export_filename is not None: scspell.export_dictionary(args.export_filename, args.base_dicts) print("Exported dictionary to '{}'".format(args.export_filename), file=sys.stderr) elif args.merge_file_ids is not None: scspell.merge_file_ids(args.merge_file_ids[0], args.merge_file_ids[1], args.override_filename, args.base_dicts, args.relative_to) elif args.rename_file is not None: scspell.rename_file(args.rename_file[0], args.rename_file[1], args.override_filename, args.base_dicts, args.relative_to) elif args.delete_files: if len(args.files) < 1: parser.error('No files specified for delete') scspell.delete_files(args.files, args.override_filename, args.base_dicts, args.relative_to) elif args.filter_out_base_dicts: scspell.filter_out_base_dicts(args.override_filename, args.base_dicts) elif len(args.files) < 1: parser.error('No files specified') else: okay = scspell.spell_check(args.files, args.override_filename, args.base_dicts, args.relative_to, args.report, args.c_escapes, args.test_input) return 0 if okay else 1