Skip to content

Commit 3666d43

Browse files
authored
fix: Fix and add flake8 to CI (#86)
1 parent b3e29d5 commit 3666d43

File tree

8 files changed

+76
-43
lines changed

8 files changed

+76
-43
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
exclude = build,venv,.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg

.gitignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
*.pyc
21
*.egg
32
*.egg-info
4-
dist
5-
eggs
6-
build
7-
sdist
3+
*.pyc
4+
.coverage
5+
.env
86
.Python
97
bin/
8+
build
9+
dist
10+
eggs
1011
include/
1112
lib/
12-
.env
13+
sdist
1314
smtpapi/VERSION.txt
1415
venv/

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ install:
1414
script:
1515
- make test
1616
- . venv/bin/activate; coverage run test/__init__.py
17+
- . venv/bin/activate; flake8 --statistics --count
1718
after_success:
1819
- codecov
1920
deploy:

examples/example.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
from smtpapi import SMTPAPIHeader
44

55
import time
6+
from os import path, sys
67

78
if __name__ == '__main__' and __package__ is None:
8-
from os import sys, path
9-
109
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
11-
from smtpapi import SMTPAPIHeader
1210

1311
header = SMTPAPIHeader()
1412

1513
# [To](http://sendgrid.com/docs/API_Reference/SMTP_API/index.html)
1614
# header.add_to('[email protected]')
1715
header.set_tos(['[email protected]', '[email protected]'])
1816

19-
# [Substitutions](http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html)
17+
# [Substitutions]
18+
# (http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html)
2019
# header.add_substitution('key', 'value')
2120
header.set_substitutions({'key': ['value1', 'value2']})
2221

23-
# [Unique Arguments](http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html)
22+
# [Unique Arguments]
23+
# (http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html)
2424
# header.add_unique_arg('key', 'value')
2525
header.set_unique_args({'key': 'value'})
2626

@@ -32,16 +32,20 @@
3232
# header.add_section('key', 'section')
3333
header.set_sections({'key1': 'section1', 'key2': 'section2'})
3434

35-
# [Filters](http://sendgrid.com/docs/API_Reference/SMTP_API/apps.html)
35+
# [Filters]
36+
# (http://sendgrid.com/docs/API_Reference/SMTP_API/apps.html)
3637
header.add_filter('filter', 'setting', 'value')
3738

38-
# [ASM Group ID](https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html)
39+
# [ASM Group ID]
40+
# (https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html)
3941
header.set_asm_group_id('value')
4042

41-
# [IP Pools](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_pools.html)
43+
# [IP Pools]
44+
# (https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_pools.html)
4245
header.set_ip_pool("testPool")
4346

44-
# [Scheduling Parameters](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
47+
# [Scheduling Parameters]
48+
# (https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
4549
# header.add_send_each_at(unix_timestamp) # must be a unix timestamp
4650
# header.set_send_each_at([]) # must be a unix timestamp
4751
header.set_send_at(int(time.time())) # must be a unix timestamp

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
dir_path = os.path.abspath(os.path.dirname(__file__))
88
readme = io.open(os.path.join(dir_path, 'README.rst'), encoding='utf-8').read()
9-
version = io.open(os.path.join(dir_path, 'VERSION.txt'), encoding='utf-8').read().strip()
9+
version = io.open(
10+
os.path.join(dir_path, 'VERSION.txt'),
11+
encoding='utf-8',
12+
).read().strip()
1013
copy_file(os.path.join(dir_path, 'VERSION.txt'),
1114
os.path.join(dir_path, 'smtpapi', 'VERSION.txt'),
1215
verbose=0)

test/__init__.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def test_add(self):
4646

4747
def test_set(self):
4848
header = SMTPAPIHeader()
49-
49+
header.set_tos([
50+
51+
52+
53+
])
5054
header.set_substitutions({
5155
"subKey": ["subValue"],
5256
"decimalKey": [decimal.Decimal("1.23456789")]
@@ -85,7 +89,11 @@ def test_license_year(self):
8589
if line.startswith('Copyright'):
8690
copyright_line = line.strip()
8791
break
88-
self.assertEqual('Copyright (C) %s, Twilio SendGrid, Inc. <[email protected]>' % datetime.datetime.now().year, copyright_line)
92+
self.assertEqual(
93+
'Copyright (C) %s, Twilio SendGrid, Inc. <[email protected]>'
94+
% datetime.datetime.now().year,
95+
copyright_line
96+
)
8997

9098

9199
class TestRepository(unittest.TestCase):
@@ -118,10 +126,17 @@ def test_repository_files_exists(self):
118126
for file_path in self.required_files:
119127
if isinstance(file_path, list):
120128
# multiple file paths: assert that any one of the files exists
121-
self.assertTrue(any(os.path.exists(f) for f in file_path),
122-
msg=self.file_not_found_message.format('" or "'.join(file_path)))
129+
self.assertTrue(
130+
any(os.path.exists(f) for f in file_path),
131+
msg=self.file_not_found_message.format(
132+
'" or "'.join(file_path)
133+
),
134+
)
123135
else:
124-
self.assertTrue(os.path.exists(file_path), msg=self.file_not_found_message.format(file_path))
136+
self.assertTrue(
137+
os.path.exists(file_path),
138+
msg=self.file_not_found_message.format(file_path),
139+
)
125140

126141

127142
if __name__ == '__main__':

test/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
sendgrid
22
coverage
3+
flake8

test/test_project.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,82 @@
11
import os
2-
3-
try:
4-
import unittest2 as unittest
5-
except ImportError:
6-
import unittest
2+
import unittest
73

84

95
class ProjectTests(unittest.TestCase):
106

117
# ./Docker or docker/Docker
12-
def test_dockerfile(self):
13-
self.assertEqual(True, os.path.isfile("./Dockerfile") or os.path.isfile("./docker/Dockerfile"))
8+
def test_docker_dir(self):
9+
self.assertTrue(
10+
os.path.isfile("./Dockerfile")
11+
or os.path.isdir("./docker/Dockerfile")
12+
)
1413

1514
# ./docker-compose.yml or ./docker/docker-compose.yml
1615
def test_docker_compose(self):
17-
self.assertEqual(True, os.path.isfile('./docker-compose.yml') or os.path.isfile('./docker/docker-compose.yml'))
16+
self.assertTrue(
17+
os.path.isfile('./docker-compose.yml')
18+
or os.path.isfile('./docker/docker-compose.yml')
19+
)
1820

1921
# ./.env_sample
2022
def test_env(self):
21-
self.assertEqual(True, os.path.isfile('./.env_sample'))
23+
self.assertTrue(os.path.isfile('./.env_sample'))
2224

2325
# ./.gitignore
2426
def test_gitignore(self):
25-
self.assertEqual(True, os.path.isfile('./.gitignore'))
27+
self.assertTrue(os.path.isfile('./.gitignore'))
2628

2729
# ./.travis.yml
2830
def test_travis(self):
29-
self.assertEqual(True, os.path.isfile('./.travis.yml'))
31+
self.assertTrue(os.path.isfile('./.travis.yml'))
3032

3133
# ./.codeclimate.yml
3234
def test_codeclimate(self):
33-
self.assertEqual(True, os.path.isfile('./.codeclimate.yml'))
35+
self.assertTrue(os.path.isfile('./.codeclimate.yml'))
3436

3537
# ./CHANGELOG.md
3638
def test_changelog(self):
37-
self.assertEqual(True, os.path.isfile('./CHANGELOG.md'))
39+
self.assertTrue(os.path.isfile('./CHANGELOG.md'))
3840

3941
# ./CODE_OF_CONDUCT.md
4042
def test_code_of_conduct(self):
41-
self.assertEqual(True, os.path.isfile('./CODE_OF_CONDUCT.md'))
43+
self.assertTrue(os.path.isfile('./CODE_OF_CONDUCT.md'))
4244

4345
# ./CONTRIBUTING.md
4446
def test_contributing(self):
45-
self.assertEqual(True, os.path.isfile('./CONTRIBUTING.md'))
47+
self.assertTrue(os.path.isfile('./CONTRIBUTING.md'))
4648

4749
# ./ISSUE_TEMPLATE.md
4850
def test_issue_template(self):
49-
self.assertEqual(True, os.path.isfile('./ISSUE_TEMPLATE.md'))
51+
self.assertTrue(os.path.isfile('./ISSUE_TEMPLATE.md'))
5052

5153
# ./LICENSE.md
5254
def test_license(self):
53-
self.assertEqual(True, os.path.isfile('./LICENSE.md') or os.path.isfile('./LICENSE.txt'))
55+
self.assertTrue(
56+
os.path.isfile('./LICENSE.md') or os.path.isfile('./LICENSE.txt')
57+
)
5458

5559
# ./PULL_REQUEST_TEMPLATE.md
5660
def test_pr_template(self):
57-
self.assertEqual(True, os.path.isfile('./PULL_REQUEST_TEMPLATE.md'))
61+
self.assertTrue(
62+
os.path.isfile('./PULL_REQUEST_TEMPLATE.md')
63+
)
5864

5965
# ./README.rst
6066
def test_readme(self):
61-
self.assertEqual(True, os.path.isfile('./README.rst'))
67+
self.assertTrue(os.path.isfile('./README.rst'))
6268

6369
# ./TROUBLESHOOTING.md
6470
def test_troubleshooting(self):
65-
self.assertEqual(True, os.path.isfile('./TROUBLESHOOTING.md'))
71+
self.assertTrue(os.path.isfile('./TROUBLESHOOTING.md'))
6672

6773
# ./USAGE.md
6874
def test_usage(self):
69-
self.assertEqual(True, os.path.isfile('./USAGE.md'))
75+
self.assertTrue(os.path.isfile('./USAGE.md'))
7076

7177
# ./VERSION.txt
7278
def test_use_cases(self):
73-
self.assertEqual(True, os.path.isfile('./VERSION.txt'))
79+
self.assertTrue(os.path.isfile('./VERSION.txt'))
7480

7581

7682
if __name__ == '__main__':

0 commit comments

Comments
 (0)