Travis CI: Add a flake8 test for unused imports (#1038)

This commit is contained in:
Christian Clauss 2019-07-25 09:49:00 +02:00 committed by Anshul
parent 46bcee0978
commit 3c8e9314b6
5 changed files with 212 additions and 221 deletions

View File

@ -6,7 +6,7 @@ before_install: pip install --upgrade pip setuptools
install: pip install -r requirements.txt
before_script:
- black --check . || true
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- flake8 . --count --select=E9,F401,F63,F7,F82 --show-source --statistics
script:
- mypy --ignore-missing-imports .
- pytest . --doctest-modules

View File

@ -16,10 +16,19 @@ while Q is non-empty:
"""
import collections
G = {'A': ['B', 'C'],
'B': ['A', 'D', 'E'],
'C': ['A', 'F'],
'D': ['B'],
'E': ['B', 'F'],
'F': ['C', 'E']}
def bfs(graph, start):
"""
>>> ''.join(sorted(bfs(G, 'A')))
'ABCDEF'
"""
explored, queue = set(), [start] # collections.deque([start])
explored.add(start)
while queue:
@ -31,11 +40,5 @@ def bfs(graph, start):
return explored
G = {'A': ['B', 'C'],
'B': ['A', 'D', 'E'],
'C': ['A', 'F'],
'D': ['B'],
'E': ['B', 'F'],
'F': ['C', 'E']}
if __name__ == '__main__':
print(bfs(G, 'A'))

View File

@ -6,8 +6,6 @@ Wikipedia reference: https://en.wikipedia.org/wiki/Volume
from math import pi
PI = pi
def vol_cube(side_length):
"""Calculate the Volume of a Cube."""
@ -39,9 +37,7 @@ def vol_right_circ_cone(radius, height):
volume = (1/3) * pi * radius^2 * height
"""
import math
return (float(1) / 3) * PI * (radius ** 2) * height
return (float(1) / 3) * pi * (radius ** 2) * height
def vol_prism(area_of_base, height):
@ -71,7 +67,7 @@ def vol_sphere(radius):
V = (4/3) * pi * r^3
Wikipedia reference: https://en.wikipedia.org/wiki/Sphere
"""
return (float(4) / 3) * PI * radius ** 3
return (float(4) / 3) * pi * radius ** 3
def vol_circular_cylinder(radius, height):
@ -80,7 +76,7 @@ def vol_circular_cylinder(radius, height):
Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
volume = pi * radius^2 * height
"""
return PI * radius ** 2 * height
return pi * radius ** 2 * height
def main():

View File

@ -39,12 +39,14 @@ goldbach(number) // Goldbach's assumption
"""
from math import sqrt
def isPrime(number):
"""
input: positive integer 'number'
returns true if 'number' is prime otherwise false.
"""
import math # for function sqrt
# precondition
assert isinstance(number,int) and (number >= 0) , \
@ -56,7 +58,7 @@ def isPrime(number):
if number <= 1:
status = False
for divisor in range(2,int(round(math.sqrt(number)))+1):
for divisor in range(2,int(round(sqrt(number)))+1):
# if 'number' divisible by 'divisor' then sets 'status'
# of false and break up the loop.
@ -143,8 +145,6 @@ def primeFactorization(number):
returns a list of the prime number factors of 'number'
"""
import math # for function sqrt
# precondition
assert isinstance(number,int) and number >= 0, \
"'number' must been an int and >= 0"
@ -497,8 +497,6 @@ def getDivisors(n):
# precondition
assert isinstance(n,int) and (n >= 1), "'n' must been int and >= 1"
from math import sqrt
ans = [] # will be returned.
for divisor in range(1,n+1):

View File

@ -3,18 +3,12 @@ Problem Statement:
Work out the first ten digits of the sum of the following one-hundred 50-digit
numbers.
"""
from __future__ import print_function
import os
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def solution(array):
"""Returns the first ten digits of the sum of the array elements.
>>> import os
>>> sum = 0
>>> array = []
>>> with open(os.path.dirname(__file__) + "/num.txt","r") as f: