Skip to content

Commit

Permalink
Add flake8, autopep8, and pycln to CI (jazzband#512)
Browse files Browse the repository at this point in the history
* Add flake8 and autopep8 to CI

* attempt to fix CI

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* use flake8 v4.0.1

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* noqa on wsgi application

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add pycln

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add --all to pycln

* fix all command

* fix precommit ci spacing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* readd test_code_gen_curl imports as comments

* manually fix PEP8 violations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* test using autopep8 to remove unused imports

* Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"

This reverts commit 2c56921.

* Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"

This reverts commit 5f42c17.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert "test using autopep8 to remove unused imports"

This reverts commit 1e9c7c4.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Archmonger and pre-commit-ci[bot] authored Oct 13, 2021
1 parent 8a8ac08 commit 2245739
Show file tree
Hide file tree
Showing 36 changed files with 123 additions and 112 deletions.
22 changes: 15 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ repos:
rev: 'v4.0.1'
hooks:
- id: check-merge-conflict
- repo: https://github.com/hadialqattan/pycln
rev: v1.0.3
hooks:
- id: pycln
args: ['--all']
- repo: https://github.com/asottile/yesqa
rev: v1.2.3
hooks:
Expand All @@ -11,7 +16,7 @@ repos:
rev: '5.9.3'
hooks:
- id: isort
args: ["--profile", "black"]
args: ['--profile', 'black']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.0.1'
hooks:
Expand Down Expand Up @@ -46,12 +51,15 @@ repos:
hooks:
- id: pyupgrade
args: ['--py36-plus', '--keep-mock']
# - repo: https://github.com/PyCQA/flake8
# rev: '3.9.2'
# hooks:
# - id: flake8
# exclude: "^docs/"
# args: ['--ignore', 'E501,E203,W503']
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: 'v1.5.7'
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: '4.0.1'
hooks:
- id: flake8
exclude: '^docs/'
- repo: git://github.com/Lucas-C/pre-commit-hooks-markup
rev: v1.0.1
hooks:
Expand Down
24 changes: 12 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,22 @@
# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'silk.tex', 'silk Documentation',
'Michael Ford', 'manual'),
('index', 'silk.tex', 'silk Documentation',
'Michael Ford', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -223,7 +223,7 @@
man_pages = [
('index', 'silk', 'silk Documentation',
['Michael Ford'], 1),
('profiling', 'Profiling', 'Profiling',
('profiling', 'Profiling', 'Profiling',
['Michael Ford'], 2),
]

Expand All @@ -237,9 +237,9 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'silk', 'silk Documentation',
'Michael Ford', 'silk', 'One line description of project.',
'Miscellaneous'),
('index', 'silk', 'silk Documentation',
'Michael Ford', 'silk', 'One line description of project.',
'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
Expand Down
1 change: 0 additions & 1 deletion project/example_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ def desc(self, obj):
desc.allow_tags = True



admin.site.register(Blind, BlindAdmin)
2 changes: 0 additions & 2 deletions project/example_app/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from django.test import TestCase

# Create your tests here.
4 changes: 2 additions & 2 deletions project/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

def main():
"""Perform the main function logic."""
venetian = Blind.objects.create(name='Venetian', child_safe=False)
roller = Blind.objects.create(name='Roller', child_safe=True)
Blind.objects.create(name='Venetian', child_safe=False)
Blind.objects.create(name='Roller', child_safe=True)


if __name__ == '__main__':
Expand Down
4 changes: 1 addition & 3 deletions project/project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
]



urlpatterns += [
path(
route='login/',
Expand All @@ -30,6 +29,5 @@
]



urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + \
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2 changes: 1 addition & 1 deletion project/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import *
from . import * # noqa: F401, F403
2 changes: 1 addition & 1 deletion project/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
END_LINE_NUM = 10

with open(__file__) as f:
ACTUAL_LINES = [l + '\n' for l in f.read().split('\n')]
ACTUAL_LINES = [line + '\n' for line in f.read().split('\n')]


class CodeTestCase(TestCase):
Expand Down
11 changes: 4 additions & 7 deletions project/tests/test_code_gen_curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
against a HTTP server that echos various components in the request.
"""

import json
import subprocess
import unittest
# import json
# import subprocess
# import unittest

# noinspection PyUnresolvedReferences
from silk.code_generation.curl import curl_cmd
# from silk.code_generation.curl import curl_cmd

# .util has disappeared so let's comment out the import for
# now since nothing is using it and it's breaking the build
# from .util import PORT, construct_echo_process




# class TestCodeGenerationCurl(unittest.TestCase):
# httpd_process = construct_echo_process()
# methods = ['GET', 'POST', 'HEAD', 'PUT', 'PATCH', 'OPTIONS', 'DELETE', 'TRACE', 'CONNECT']
Expand Down
1 change: 0 additions & 1 deletion project/tests/test_config_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_default_authorisation(self):
response = self.client.get(silky_reverse('requests'))
self.assertEqual(response.status_code, 200)


def test_custom_authorisation(self):
SilkyConfig().SILKY_AUTHENTICATION = True
SilkyConfig().SILKY_AUTHORISATION = True
Expand Down
1 change: 1 addition & 0 deletions project/tests/test_config_max_body_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_max_request(self):
request_model = RequestModelFactory(mock_request).construct_request_model()
self.assertFalse(request_model.raw_body)


class TestMaxBodySizeResponse(TestCase):

def setUp(self):
Expand Down
6 changes: 3 additions & 3 deletions project/tests/test_config_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def _execute_request(self):
def test_enabled(self):
SilkyConfig().SILKY_META = True
r = self._execute_request()
self.assertTrue(r.meta_time is not None or
r.meta_num_queries is not None or
r.meta_time_spent_queries is not None)
self.assertTrue(r.meta_time is not None
or r.meta_num_queries is not None
or r.meta_time_spent_queries is not None)

def test_disabled(self):
SilkyConfig().SILKY_META = False
Expand Down
8 changes: 4 additions & 4 deletions project/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestDbQueries(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
objects = BlindFactory.create_batch(size=5)
BlindFactory.create_batch(size=5)
SilkyConfig().SILKY_META = False

def test_profile_request_to_db(self):
Expand All @@ -27,7 +27,7 @@ def test_profile_request_to_db(self):
with silk_profile(name='test_profile'):
resp = client.get(reverse('example_app:index'))

profile = list(DataCollector().profiles.values())[0]
DataCollector().profiles.values()
assert len(resp.context['blinds']) == 5


Expand All @@ -36,7 +36,7 @@ class TestAnalyzeQueries(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
objects = BlindFactory.create_batch(size=5)
BlindFactory.create_batch(size=5)
SilkyConfig().SILKY_META = False
SilkyConfig().SILKY_ANALYZE_QUERIES = True

Expand All @@ -52,5 +52,5 @@ def test_analyze_queries(self):
with silk_profile(name='test_profile'):
resp = client.get(reverse('example_app:index'))

profile = list(DataCollector().profiles.values())[0]
DataCollector().profiles.values()
assert len(resp.context['blinds']) == 5
4 changes: 2 additions & 2 deletions project/tests/test_end_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_raw(self):
request_id = request_query_data['id']
url = reverse('silk:raw', kwargs={
'request_id': request_id
})+'?typ=request&subtyp=processed'
}) + '?typ=request&subtyp=processed'
response = self.client.get(url)
code = response.status_code
self.assertTrue(code == 200)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_profile_sql_detail(self):
profile_id = profile_query_data['id']
sql_id = random.choice(models.SQLQuery.objects.filter(profiles=profile_id)).pk
response = self.client.get(silky_reverse('profile_sql_detail', kwargs={'profile_id': profile_id,
'sql_id': sql_id}))
'sql_id': sql_id}))
self.assertTrue(response.status_code == 200)

def test_profiling(self):
Expand Down
3 changes: 2 additions & 1 deletion project/tests/test_execute_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from silk.collector import DataCollector
from silk.models import Request, SQLQuery
from silk.sql import connection, execute_sql
from silk.sql import execute_sql

from .util import delete_all_models

Expand All @@ -18,6 +18,7 @@ def mock_sql():
mock_sql_query.as_sql = Mock(return_value=(query_string, ()))
return mock_sql_query, query_string


def call_execute_sql(cls, request):
DataCollector().configure(request=request)
delete_all_models(SQLQuery)
Expand Down
1 change: 1 addition & 0 deletions project/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_method_filter(self):
filtered = query_set.filter(method_filter)
self.assertEqual(len(list(expected)), filtered.count())


class TestRequestAfterDateFilter(TestCase):
def assertFilter(self, dt, f):
requests = models.Request.objects.filter(f)
Expand Down
3 changes: 1 addition & 2 deletions project/tests/test_lib/mock_suite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import calendar
import json
import os
import random
Expand Down Expand Up @@ -116,7 +115,7 @@ def mock_profile(self, request=None):
dynamic=dynamic,
end_line_num=6 if dynamic else None,
exception_raised=random.choice([True, False])
)
)
self.mock_sql_queries(profile=profile, n=random.randint(0, 10))
return profile

Expand Down
14 changes: 6 additions & 8 deletions project/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# UUID_MAX_LENGTH = 36

# TODO move to separate file test and collection it self


class CaseInsensitiveDictionaryTest:
pass

Expand Down Expand Up @@ -79,14 +81,6 @@ def test_time_spent_on_sql_queries_if_has_related_SQLQueries_with_no_time_taken(
with self.assertRaises(TypeError):
self.obj.time_spent_on_sql_queries

def test_time_spent_on_sql_queries_if_has_related_SQLQueries_and_time_taken(self):

query1 = SQLQueryFactory(time_taken=3.5)
query2 = SQLQueryFactory(time_taken=1.5)
self.obj.queries.add(query1, query2)

self.assertEqual(self.obj.time_spent_on_sql_queries, 0)

def test_time_spent_on_sql_queries_if_has_related_SQLQueries_and_time_taken(self):

query1 = SQLQueryFactory(time_taken=3.5)
Expand Down Expand Up @@ -249,12 +243,16 @@ class SQLQueryManagerTest(TestCase):

def test_if_no_args_passed(self):
pass

def test_if_one_arg_passed(self):
pass

def if_a_few_args_passed(self):
pass

def if_objs_kw_arg_passed(self):
pass

def if_not_the_objs_kw_arg_passed(self):
pass

Expand Down
6 changes: 4 additions & 2 deletions project/tests/test_profile_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def _profile(cls):
# create profile - we don't need to convert a django file field to a temp file
# just use the filename of the temp file already created
@contextmanager
def dummy(_): yield filename
def dummy(_):
yield filename
return _create_profile(filename, dummy)

@classmethod
Expand All @@ -61,6 +62,7 @@ def _mock_file(cls, data):
Get a mock object that looks like a file but returns data when read is called.
"""
i = [0]

def read(n):
if not i[0]:
i[0] += 1
Expand All @@ -76,7 +78,7 @@ def test_create_dot(self):
"""
Verify that a dot file is correctly created from pstats data stored in a file field.
"""
with self._stats_file() as filename:
with self._stats_file():

try:
# create dot
Expand Down
4 changes: 1 addition & 3 deletions project/tests/test_sensitive_data_in_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.test import TestCase

from silk.config import SilkyConfig
from silk.model_factory import RequestModelFactory, ResponseModelFactory
from silk.model_factory import RequestModelFactory

DJANGO_META_CONTENT_TYPE = 'CONTENT_TYPE'
HTTP_CONTENT_TYPE = 'Content-Type'
Expand Down Expand Up @@ -76,7 +76,6 @@ def test_mask_credentials_masks_sensitive_values_listed_in_settings(self):
self.assertEqual(expected, self._mask(body))



class MaskCredentialsInJsonTest(TestCase):
def tearDown(self):
SilkyConfig().SILKY_SENSITIVE_KEYS = DEFAULT_SENSITIVE_KEYS
Expand Down Expand Up @@ -124,7 +123,6 @@ def test_mask_credentials_masks_sensitive_values_listed_in_settings(self):
self.assertNotIn("hidethis", self._mask({"foo": "hidethis"}))



class TestEncodingForRequests(TestCase):
"""
Check that the RequestModelFactory masks sensitive data
Expand Down
2 changes: 1 addition & 1 deletion project/tests/test_silky_middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest.mock import Mock, patch
from unittest.mock import patch

from django.test import TestCase, override_settings
from django.urls import reverse
Expand Down
Loading

0 comments on commit 2245739

Please sign in to comment.