Skip to content

Travis CI: Run black, doctest, flake8, mypy, and pytest #964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bc437e4
Travis CI: Add type checking with mypy
cclauss Jul 6, 2019
5dd8090
Create requirements.txt
cclauss Jul 6, 2019
d3d5a39
script: mypy --ignore-missing-stubs=cv2,numpy .
cclauss Jul 6, 2019
3f32aa8
Delete requirements.txt
cclauss Jul 6, 2019
ed1e00a
script: mypy --ignore-missing-imports .
cclauss Jul 6, 2019
6950950
Run doctests
cclauss Jul 6, 2019
d612c3a
Disable doctest -v other/detecting_english_programmatically.py
cclauss Jul 6, 2019
6846fcc
Pytest
cclauss Jul 6, 2019
9c7f9da
No |
cclauss Jul 6, 2019
d371f76
pytest || true
cclauss Jul 6, 2019
276b248
Run black doctest flake8 mypy pytest
cclauss Jul 6, 2019
5ca5b43
after_success: Build Directory.md
cclauss Jul 6, 2019
5ad53a7
Typo in filename: Dictionary.txt --> dictionary.txt'
cclauss Jul 6, 2019
047216f
python -m doctest -v
cclauss Jul 6, 2019
bd02765
pip install black flake8 mypy pytest
cclauss Jul 6, 2019
9994794
pytest --doctest-glob='*.py'
cclauss Jul 6, 2019
86bdb71
pytest --doctest-modules
cclauss Jul 6, 2019
19b45dd
pytest --doctest-modules ./sorts
cclauss Jul 6, 2019
5a1a398
pytest --doctest-modules ./ciphers ./other ./searches ./sorts ./strin…
cclauss Jul 6, 2019
a37327d
if __name__ == "__main__":
cclauss Jul 6, 2019
002287d
if __name__ == "__main__":
cclauss Jul 6, 2019
cec7e16
if __name__ == '__main__':
cclauss Jul 6, 2019
28d9e6d
if __name__ == '__main__':
cclauss Jul 6, 2019
1c27abc
if __name__ == '__main__':
cclauss Jul 6, 2019
704bf00
Create requirements.txt
cclauss Jul 6, 2019
3456316
Update requirements.txt
cclauss Jul 6, 2019
769f66d
if __name__ == "__main__":
cclauss Jul 6, 2019
122bf27
Lose the doctests
cclauss Jul 6, 2019
9ae08f3
if __name__ == '__main__':
cclauss Jul 6, 2019
03b4bdd
Remove print-a-tuple
cclauss Jul 6, 2019
8b55aff
doctest: Added missing spaces
cclauss Jul 6, 2019
33a8723
Update tabu_search.py
cclauss Jul 6, 2019
32349c1
The >>> are not doctests so change to >>)
cclauss Jul 6, 2019
5bc5634
Travis CI: Run black, doctest, flake8, mypy, and pytest
cclauss Jul 6, 2019
976f914
Link to the separate DIRECTORY.md file
cclauss Jul 7, 2019
364014b
Merge branch 'master' into mypy-on-Travis-CI
cclauss Jul 7, 2019
fab6bc2
Update README.md
poyea Jul 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
language: python
dist: xenial # required for Python >= 3.7
python: 3.7
install: pip install flake8
script: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
cache: pip
install: pip install -r requirements.txt
before_script:
- black --check . || true
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these lines are in before_script and why black has || true?

Copy link
Member Author

@cclauss cclauss Jul 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successful before_script results are hidden under twisties so they do not clutter the error log so contributors can go straight to the heart of the problems.

black will fail badly in the near term because we do not mandate formatted code. However, we want to be able to understand improvement as we make it without failing the build.

script:
- mypy --ignore-missing-imports .
- pytest --doctest-modules ./ciphers ./other ./searches ./sorts ./strings
Copy link
Contributor

@sirex sirex Jul 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it would be nice to add pytest-cov and generate coverage report?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am not a fan of coverage tools. We do not mandate tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sirex It has been a busy two weeks but now we have 132 pytests passing so I think we could add pytest-cov to Travis CI as you suggested above. Please consider submitting a pull request that modifies .travis.yml so that it runs pytest-cov.

after_success:
- python ./~script.py
- cat DIRECTORY.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well if we want to change the directory while merging, do we need a bot?

4 changes: 3 additions & 1 deletion ciphers/Atbash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ def Atbash():
output+=i
print(output)

Atbash()

if __name__ == '__main__':
Atbash()
5 changes: 4 additions & 1 deletion ciphers/caesar_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ def main():
elif choice == '4':
print ("Goodbye.")
break
main()


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion other/detecting_english_programmatically.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def loadDictionary():
path = os.path.split(os.path.realpath(__file__))
englishWords = {}
with open(path[0] + '/Dictionary.txt') as dictionaryFile:
with open(path[0] + '/dictionary.txt') as dictionaryFile:
for word in dictionaryFile.read().split('\n'):
englishWords[word] = None
return englishWords
Expand Down
17 changes: 9 additions & 8 deletions other/sierpinski_triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
import turtle
import sys
PROGNAME = 'Sierpinski Triangle'
if len(sys.argv) !=2:
raise Exception('right format for using this script: $python fractals.py <int:depth_for_fractal>')

myPen = turtle.Turtle()
myPen.ht()
myPen.speed(5)
myPen.pencolor('red')

points = [[-175,-125],[0,175],[175,-125]] #size of triangle

Expand Down Expand Up @@ -64,4 +57,12 @@ def triangle(points,depth):
depth-1)


triangle(points,int(sys.argv[1]))
if __name__ == '__main__':
if len(sys.argv) !=2:
raise ValueError('right format for using this script: '
'$python fractals.py <int:depth_for_fractal>')
myPen = turtle.Turtle()
myPen.ht()
myPen.speed(5)
myPen.pencolor('red')
triangle(points,int(sys.argv[1]))
4 changes: 2 additions & 2 deletions other/tower_of_hanoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def moveTower(height, fromPole, toPole, withPole):
moveTower(height-1, withPole, toPole, fromPole)

def moveDisk(fp,tp):
print(('moving disk from', fp, 'to', tp))
print('moving disk from', fp, 'to', tp)

def main():
height = int(input('Height of hanoi: '))
height = int(input('Height of hanoi: ').strip())
moveTower(height, 'A', 'B', 'C')

if __name__ == '__main__':
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
black
flake8
matplotlib
mypy
numpy
pytest
4 changes: 2 additions & 2 deletions searches/tabu_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def generate_neighbours(path):
and the cost (distance) for each neighbor.

Example of dict_of_neighbours:
>>> dict_of_neighbours[a]
>>) dict_of_neighbours[a]
[[b,20],[c,18],[d,22],[e,26]]

This indicates the neighbors of node (city) 'a', which has neighbor the node 'b' with distance 20,
Expand Down Expand Up @@ -130,7 +130,7 @@ def find_neighborhood(solution, dict_of_neighbours):


Example:
>>> find_neighborhood(['a','c','b','d','e','a'])
>>) find_neighborhood(['a','c','b','d','e','a'])
[['a','e','b','d','c','a',90], [['a','c','d','b','e','a',90],['a','d','b','c','e','a',93],
['a','c','b','e','d','a',102], ['a','c','e','d','b','a',113], ['a','b','c','d','e','a',93]]

Expand Down
25 changes: 13 additions & 12 deletions sorts/Bitonic_Sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ def sort(a, N, up):
bitonicSort(a, 0, N, up)


# Driver code to test above
a = []

n = int(input())
for i in range(n):
a.append(int(input()))
up = 1

sort(a, n, up)
print("\n\nSorted array is")
for i in range(n):
print("%d" % a[i])
if __name__ == "__main__":
# Driver code to test above
a = []

n = int(input().strip())
for i in range(n):
a.append(int(input().strip()))
up = 1

sort(a, n, up)
print("\n\nSorted array is")
for i in range(n):
print("%d" % a[i])
2 changes: 1 addition & 1 deletion sorts/bubble_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def bubble_sort(collection):
[-45, -5, -2]

>>> bubble_sort([-23,0,6,-4,34])
[-23,-4,0,6,34]
[-23, -4, 0, 6, 34]
"""
length = len(collection)
for i in range(length-1):
Expand Down