Skip to content

Commit 5164467

Browse files
committed
Initial testing checking
1 parent 2868045 commit 5164467

6 files changed

Lines changed: 121 additions & 17 deletions

File tree

.github/workflows/python-app.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python testing
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python 3.9
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: 3.9
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install flake8
27+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28+
pip install -e .
29+
- name: Lint with flake8
30+
run: |
31+
# stop the build if there are Python syntax errors or undefined names
32+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33+
# exit-zero treats all errors as warnings.
34+
flake8 . --count --exit-zero --max-complexity=10 --statistics
35+
- name: Run tests
36+
run: |
37+
python -m unittest discover -s tests

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
# SimpleITKSpellChecking
22

3+
![python testing](https://github.com/SimpleITK/SimpleITKSpellChecking/actions/workflows/python-app.yml/badge.svg)
4+
5+
36
A script that automatically spell checks the comments of a code base.
47
It is intended to be run on the SimpleITK and ITK code bases.
58

69
Here is how it is typically run:
710

811
python codespell.py --exclude Ancillary $SIMPLEITK_SOURCE_DIR/Code
912

10-
This will recursively find all the '.h' files in a directory, extract
11-
the C/C++ comments from the code and run a spell checker on them.
12-
The '--exclude' flag tells the script to ignore any file that has
13-
'Ancillary' in it's full path name. This flag will accept any
13+
This command will recursively find all the '.h' files in a directory,
14+
extract the C/C++ comments from the code, and run a spell checker on them.
15+
The **'--exclude'** flag tells the script to ignore any file that has
16+
'Ancillary' in its full path name. This flag will accept any
1417
regular expression.
1518

16-
In addition to pyenchant's English dictionary, we use the words in
17-
**additional_dictionary.txt**. These are proper names and technical
18-
terms harvest by hand from SimpleITK and ITK.
19+
In addition to pyenchant's English dictionary, we use the words in
20+
**additional_dictionary.txt**. These words are proper names and
21+
technical terms harvest by hand from the SimpleITK and ITK code bases.
1922

20-
In addition to checking each word against the dictionary, if a word
21-
fails, we try two additional checks.
23+
If a word is not found in the dictionaries, we try two additional checks.
2224

23-
First, if the word starts with some know prefix, the prefix is removed
24-
and the remaining word is checked. The prefixes currently checked
25-
are 'sitk', 'itk', and 'vtk'. Additional prefixes can be specified
26-
with the '--prefix' command line argument.
25+
1. If the word starts with some known prefix, the prefix is removed
26+
...and the remaining word is checked against the dictionary. The prefixes
27+
...used by default are **'sitk'**, **'itk'**, and **'vtk'**. Additional
28+
...prefixes can be specified with the **'--prefix'** command line argument.
2729

28-
Second, we attempt to split the word by capitalization and check each
29-
sub-word. This is an attempt to detect camel-case words such as
30-
'GetArrayFromImage', which would get split into 'Get', 'Array', 'From',
31-
and 'Image'. Camel-case words are very commonly used for code elements.
30+
2. We attempt to split the word by capitalization and check each
31+
...sub-word against the dictionary. This method is an attempt to detect
32+
...camel-case words such as 'GetArrayFromImage', which would get split into
33+
...'Get', 'Array', 'From', and 'Image'. Camel-case words are very commonly
34+
...used for code elements.

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# tests

tests/dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TarHeels

tests/example.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
// Mary had a little lamb
4+
//
5+
// Prefix test words:
6+
// sitkBanana
7+
// vtkApple
8+
// itkPineapple
9+
//
10+
// Camel case test word:
11+
// CamelCaseTestWord
12+
//
13+
// Prefix and camel case test word:
14+
// sitkWhiskeyTangoFoxtrot
15+
//
16+
// Dictionary test word:
17+
// BinaryFillholeImageFilter
18+
//
19+
// Additional dictionary test word:
20+
// TarHeels
21+
22+
#include <stdio.h>
23+
24+
int test_int;
25+
int hello_world() {
26+
// Sup, bro?
27+
print("Mmmm, pie.");
28+
}
29+

tests/test_codespell.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import unittest
2+
import subprocess
3+
import os
4+
5+
6+
class TestCodespell(unittest.TestCase):
7+
@classmethod
8+
def setUpClass(self):
9+
print("Setting up codespell tests")
10+
11+
@classmethod
12+
def tearDownClass(cls):
13+
print("Tearing down dicom2stl tests")
14+
15+
def test_codespell(self):
16+
print("Codespell test")
17+
cwd = os.getcwd()
18+
print(cwd)
19+
runresult = subprocess.run(
20+
[
21+
"python",
22+
"codespell.py",
23+
"--verbose",
24+
"--dict",
25+
"tests/dict.txt",
26+
"tests/example.h"
27+
]
28+
)
29+
print("Return code:", runresult.returncode)
30+
if runresult.returncode:
31+
self.fail("codespell process returned bad code")
32+
33+

0 commit comments

Comments
 (0)