diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..47be0b2 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +exclude = build,venv,.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg diff --git a/.gitignore b/.gitignore index e6f4e3e..301d0e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,15 @@ -*.pyc *.egg *.egg-info -dist -eggs -build -sdist +*.pyc +.coverage +.env .Python bin/ +build +dist +eggs include/ lib/ -.env +sdist smtpapi/VERSION.txt venv/ diff --git a/.travis.yml b/.travis.yml index caa97ac..3f53f34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ install: script: - make test - . venv/bin/activate; coverage run test/__init__.py + - . venv/bin/activate; flake8 --statistics --count after_success: - codecov deploy: diff --git a/examples/example.py b/examples/example.py index 719eb17..07c3b15 100644 --- a/examples/example.py +++ b/examples/example.py @@ -3,12 +3,10 @@ from smtpapi import SMTPAPIHeader import time +from os import path, sys if __name__ == '__main__' and __package__ is None: - from os import sys, path - sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) - from smtpapi import SMTPAPIHeader header = SMTPAPIHeader() @@ -16,11 +14,13 @@ # header.add_to('test@example.com') header.set_tos(['test1@example.com', 'test2@example.com']) -# [Substitutions](http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html) +# [Substitutions] +# (http://sendgrid.com/docs/API_Reference/SMTP_API/substitution_tags.html) # header.add_substitution('key', 'value') header.set_substitutions({'key': ['value1', 'value2']}) -# [Unique Arguments](http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html) +# [Unique Arguments] +# (http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html) # header.add_unique_arg('key', 'value') header.set_unique_args({'key': 'value'}) @@ -32,16 +32,20 @@ # header.add_section('key', 'section') header.set_sections({'key1': 'section1', 'key2': 'section2'}) -# [Filters](http://sendgrid.com/docs/API_Reference/SMTP_API/apps.html) +# [Filters] +# (http://sendgrid.com/docs/API_Reference/SMTP_API/apps.html) header.add_filter('filter', 'setting', 'value') -# [ASM Group ID](https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html) +# [ASM Group ID] +# (https://sendgrid.com/docs/User_Guide/advanced_suppression_manager.html) header.set_asm_group_id('value') -# [IP Pools](https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_pools.html) +# [IP Pools] +# (https://sendgrid.com/docs/API_Reference/Web_API_v3/IP_Management/ip_pools.html) header.set_ip_pool("testPool") -# [Scheduling Parameters](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) +# [Scheduling Parameters] +# (https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) # header.add_send_each_at(unix_timestamp) # must be a unix timestamp # header.set_send_each_at([]) # must be a unix timestamp header.set_send_at(int(time.time())) # must be a unix timestamp diff --git a/setup.py b/setup.py index da73644..50b5a32 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,10 @@ dir_path = os.path.abspath(os.path.dirname(__file__)) readme = io.open(os.path.join(dir_path, 'README.rst'), encoding='utf-8').read() -version = io.open(os.path.join(dir_path, 'VERSION.txt'), encoding='utf-8').read().strip() +version = io.open( + os.path.join(dir_path, 'VERSION.txt'), + encoding='utf-8', +).read().strip() copy_file(os.path.join(dir_path, 'VERSION.txt'), os.path.join(dir_path, 'smtpapi', 'VERSION.txt'), verbose=0) diff --git a/test/__init__.py b/test/__init__.py index d75dfb3..149d225 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -46,7 +46,11 @@ def test_add(self): def test_set(self): header = SMTPAPIHeader() - header.set_tos(["test@email.com", "test2@email.com", "test3@email.com"]) + header.set_tos([ + "test@email.com", + "test2@email.com", + "test3@email.com", + ]) header.set_substitutions({ "subKey": ["subValue"], "decimalKey": [decimal.Decimal("1.23456789")] @@ -85,7 +89,11 @@ def test_license_year(self): if line.startswith('Copyright'): copyright_line = line.strip() break - self.assertEqual('Copyright (C) %s, Twilio SendGrid, Inc. ' % datetime.datetime.now().year, copyright_line) + self.assertEqual( + 'Copyright (C) %s, Twilio SendGrid, Inc. ' + % datetime.datetime.now().year, + copyright_line + ) class TestRepository(unittest.TestCase): @@ -118,10 +126,17 @@ def test_repository_files_exists(self): for file_path in self.required_files: if isinstance(file_path, list): # multiple file paths: assert that any one of the files exists - self.assertTrue(any(os.path.exists(f) for f in file_path), - msg=self.file_not_found_message.format('" or "'.join(file_path))) + self.assertTrue( + any(os.path.exists(f) for f in file_path), + msg=self.file_not_found_message.format( + '" or "'.join(file_path) + ), + ) else: - self.assertTrue(os.path.exists(file_path), msg=self.file_not_found_message.format(file_path)) + self.assertTrue( + os.path.exists(file_path), + msg=self.file_not_found_message.format(file_path), + ) if __name__ == '__main__': diff --git a/test/requirements.txt b/test/requirements.txt index 5b3644a..89035cf 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,2 +1,3 @@ sendgrid coverage +flake8 diff --git a/test/test_project.py b/test/test_project.py index 85feda5..fdd3684 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -1,76 +1,82 @@ import os - -try: - import unittest2 as unittest -except ImportError: - import unittest +import unittest class ProjectTests(unittest.TestCase): # ./Docker or docker/Docker - def test_dockerfile(self): - self.assertEqual(True, os.path.isfile("./Dockerfile") or os.path.isfile("./docker/Dockerfile")) + def test_docker_dir(self): + self.assertTrue( + os.path.isfile("./Dockerfile") + or os.path.isdir("./docker/Dockerfile") + ) # ./docker-compose.yml or ./docker/docker-compose.yml def test_docker_compose(self): - self.assertEqual(True, os.path.isfile('./docker-compose.yml') or os.path.isfile('./docker/docker-compose.yml')) + self.assertTrue( + os.path.isfile('./docker-compose.yml') + or os.path.isfile('./docker/docker-compose.yml') + ) # ./.env_sample def test_env(self): - self.assertEqual(True, os.path.isfile('./.env_sample')) + self.assertTrue(os.path.isfile('./.env_sample')) # ./.gitignore def test_gitignore(self): - self.assertEqual(True, os.path.isfile('./.gitignore')) + self.assertTrue(os.path.isfile('./.gitignore')) # ./.travis.yml def test_travis(self): - self.assertEqual(True, os.path.isfile('./.travis.yml')) + self.assertTrue(os.path.isfile('./.travis.yml')) # ./.codeclimate.yml def test_codeclimate(self): - self.assertEqual(True, os.path.isfile('./.codeclimate.yml')) + self.assertTrue(os.path.isfile('./.codeclimate.yml')) # ./CHANGELOG.md def test_changelog(self): - self.assertEqual(True, os.path.isfile('./CHANGELOG.md')) + self.assertTrue(os.path.isfile('./CHANGELOG.md')) # ./CODE_OF_CONDUCT.md def test_code_of_conduct(self): - self.assertEqual(True, os.path.isfile('./CODE_OF_CONDUCT.md')) + self.assertTrue(os.path.isfile('./CODE_OF_CONDUCT.md')) # ./CONTRIBUTING.md def test_contributing(self): - self.assertEqual(True, os.path.isfile('./CONTRIBUTING.md')) + self.assertTrue(os.path.isfile('./CONTRIBUTING.md')) # ./ISSUE_TEMPLATE.md def test_issue_template(self): - self.assertEqual(True, os.path.isfile('./ISSUE_TEMPLATE.md')) + self.assertTrue(os.path.isfile('./ISSUE_TEMPLATE.md')) # ./LICENSE.md def test_license(self): - self.assertEqual(True, os.path.isfile('./LICENSE.md') or os.path.isfile('./LICENSE.txt')) + self.assertTrue( + os.path.isfile('./LICENSE.md') or os.path.isfile('./LICENSE.txt') + ) # ./PULL_REQUEST_TEMPLATE.md def test_pr_template(self): - self.assertEqual(True, os.path.isfile('./PULL_REQUEST_TEMPLATE.md')) + self.assertTrue( + os.path.isfile('./PULL_REQUEST_TEMPLATE.md') + ) # ./README.rst def test_readme(self): - self.assertEqual(True, os.path.isfile('./README.rst')) + self.assertTrue(os.path.isfile('./README.rst')) # ./TROUBLESHOOTING.md def test_troubleshooting(self): - self.assertEqual(True, os.path.isfile('./TROUBLESHOOTING.md')) + self.assertTrue(os.path.isfile('./TROUBLESHOOTING.md')) # ./USAGE.md def test_usage(self): - self.assertEqual(True, os.path.isfile('./USAGE.md')) + self.assertTrue(os.path.isfile('./USAGE.md')) # ./VERSION.txt def test_use_cases(self): - self.assertEqual(True, os.path.isfile('./VERSION.txt')) + self.assertTrue(os.path.isfile('./VERSION.txt')) if __name__ == '__main__':