[Patchew-devel] [PATCH 2/2] Apply PEP8 to tests modules

Caio Carrara posted 2 patches 5 years, 10 months ago
[Patchew-devel] [PATCH 2/2] Apply PEP8 to tests modules
Posted by Caio Carrara 5 years, 10 months ago
The most of the changes in this commit are related with indentation and
whitespaces. However it was also necessary to fix how the import from
patchewtest members was implemented.

Before this change each test module was appending to sys.path the tests
directory so it was possible to import the base class PatchewTestCase.
However we can accomplish the same without change the sys.path
attribute. It's just a matter of turn tests directory into a Python
package (adding __init__.py file into it) and use the import statement
with relative imports as following:

    `from .patchewtest import PatchewTestcase`

The changes were validated running the tests with the following command:
`./manage.py test tests`.

Signed-off-by: Caio Carrara <ccarrara@redhat.com>
---
 tests/__init__.py                        |   0
 tests/data/0016-nested-multipart.mbox.gz | Bin 2122 -> 2118 bytes
 tests/patchewtest.py                     |  34 ++++----
 tests/test_ansi2html.py                  |   1 +
 tests/test_custom_tags.py                |   8 +-
 tests/test_diff.py                       |   7 +-
 tests/test_git.py                        |  11 ++-
 tests/test_import.py                     |  11 +--
 tests/test_mbox.py                       |  14 ++--
 tests/test_message.py                    |   5 +-
 tests/test_model.py                      |   5 +-
 tests/test_project.py                    |   4 +-
 tests/test_rest.py                       |  94 ++++++++++++++---------
 tests/test_tags.py                       |   8 +-
 tests/test_testing.py                    |  58 ++++++++------
 15 files changed, 153 insertions(+), 107 deletions(-)
 create mode 100644 tests/__init__.py

diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/data/0016-nested-multipart.mbox.gz b/tests/data/0016-nested-multipart.mbox.gz
index 40ee55c1d96d9fa3bd205199cd00f8bb0af43740..d7ad6c053737dab992afd12df106db01eb47030c 100644
GIT binary patch
delta 599
zcmV-d0;v7U5XKM)ABzYGc?JJlu?YPIe-2{ZYM+$>=N^k~4-Ejh4P_moaqQ*`l2T+c
z4_XXOxo1-wJw9rf2deY3h<RDkH0}~AuOQ*Ww692Bt~lUj7+7UtRtwLUvJL+IL34U{
zAnqeZB6_g>a3GM(-hQ~<p_!cq$;R*d9*Ud*$O;j8xbr9;WU#Ua8*!57#P%aNf8Vd7
z|E3|p0*^!UxO<LD-Q(`@d22EqnbkQcj-qNu859-(Kr^}mz34X<tp^R$3>b}$Sur@?
zEXYr`7sUTkxmYX&$^x(YSp>gs>Kqpg&Gli+JZ!gG&QV~Rw%zM@(-ZT$J!9hh;x5sS
z(s3|lLn%ILg`qq<6I*R>HvDzYe+{KO>Mq<`Z@knq^-Lk7&}^$gE%Bn7xK<YGUA^x{
zy0%V_f0~ok_)u-(;rOU~zD}t>o1Agu;~+e>?bduWiCc7Nj8+#HzB3@xsTnI$HqhM@
zRk`WsWMR0&r06b!6F<CNrgX`MhPCW*+G%upb34+`9X0b?XG$#h>dA23e?G3+cQ@1P
zk$d7zuNPT3O6234XgEKeSPR8iz+5DL?wqCEn$DIUIqI#b?RnGN^Y|9N9NpBiyDL?5
zFJ0%b(}^xy;bGKR%xB$;c`X#rt+hW4JN@}|9B_suIc;^(b=Nh+Oh<ROsXiW#7co7%
zJWDj=>UOMM_E&~mpHB7AMait(mRep`Q<#CxX%R2Dt6{-HdZG`<7rnFF8*C<5=OQ&&
lY=<r1J2>DD<c1S(=wzOE-Xhai>ZTOq{tFH$e#Eg8006AWClUYv

delta 603
zcmV-h0;K)M5Xuk;ABzYGRu!CCu?YPIfA0H%BywD<eOAW2{QOvQduRaoZ7A*#jbk@o
zkdz{mdC+KR$~~Li=<!j*JP@9jMa;{Rrg4{0e+3C2W`0HWa?t@_!@w%bvs!z;lyivH
zAGD}<$KpO>B%%k~4+jFt?Cpo!9h%u`kZk<E@1)2HfU*#ghdYnrK?aL^un{MDe@<*a
zg7f_<2X7hzEburqkGton)IIJVpSLE{ky)LC;wY*%l|f+v05qd3(2IU!-Fnb4&4AbF
zm=%NL&6@mVhe7-=m5aqfpe*pJA4l*Tr_OP~&|Dw3%)@r8<s1d3Y1_SiH$5@0+cPH4
zFYXfUC>;k=Hk9I{Rv5~&GqKh7e`dp9=iE@bqwd13^~Os*Q_mDK3eC0})DkbMiECw{
z-qrhVq-*Q+_@_BpjStlp9*&Q?=j)XEv&k7ZJ`TcD+iuNAlek5P#%OhM;X4B|otm*C
zWdq$kQI(s1P8NncOp5LzIPt^VWlEQ9Xjsc0r=3QpH@740+)*>Xb*98}f3Kbl*X`q)
zeRngx9=Rvp^m>tnqeMQwiH7sjiM3FS1x!cc=gwKmt?6v(k)z&<+MYMPJ&$kU%h63O
zySq{~_tJF^JDupV6&^;7#eCMinAbw_+*<p?u+yJU#{p+plG9cfU3XnG%ye{jo9g4?
zcoEaH%d<o?u5QQLWq)P3N%iSe51q`)ZK>sDHH8`2oEGtdyBZcOq$m1te9=3*y}@R3
pbuLna#dg^8y@LbpKyEnkhEC>r=PfdQrEW?w?!VCGVV}1X000fwH{}2T

diff --git a/tests/patchewtest.py b/tests/patchewtest.py
index fc6de3e..ade039d 100644
--- a/tests/patchewtest.py
+++ b/tests/patchewtest.py
@@ -18,30 +18,32 @@ import json
 import atexit
 import gzip
 
+import django
+import django.test as dj_test
+from django.contrib.auth.models import User, Group
+import rest_framework.test
+
+from api.models import Message, Result, Project
+
+
 BASE_DIR = os.path.join(os.path.dirname(__file__), "..")
+PATCHEW_CLI = os.path.join(BASE_DIR, "patchew-cli")
+RUN_DIR = tempfile.mkdtemp()
 
 sys.path.append(BASE_DIR)
 
 os.environ["PATCHEW_TEST"] = "1"
+os.environ["PATCHEW_TEST_DATA_DIR"] = os.path.join(RUN_DIR, "patchew-data")
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "patchew.settings")
-import django
 
 django.setup()
 
-import django.test
-from django.contrib.auth.models import User, Group
-import rest_framework.test
-from api.models import *
 
-PATCHEW_CLI = os.path.join(BASE_DIR, "patchew-cli")
-RUN_DIR = tempfile.mkdtemp()
-os.environ["PATCHEW_TEST_DATA_DIR"] = os.path.join(RUN_DIR, "patchew-data")
-
-class PatchewTestCase(django.test.LiveServerTestCase):
+class PatchewTestCase(dj_test.LiveServerTestCase):
     user = "admin"
     email = "admin@test"
     password = "adminpass"
-    client = django.test.Client()
+    client = dj_test.Client()
     api_client = rest_framework.test.APIClient()
 
     REST_BASE = 'http://testserver/api/v1/'
@@ -79,8 +81,11 @@ class PatchewTestCase(django.test.LiveServerTestCase):
     def check_cli(self, args, rc=0, stdout=None, stderr=None):
         assert(isinstance(args, list))
         r, a, b = self.cli(args)
-        self.assertEqual(r, rc,
-            "Exit code {} != expected {}, stdout:\n{}\nstderr:\n{}\n".format(r, rc, a, b))
+        self.assertEqual(
+            r,
+            rc,
+            "Exit code {} != expected {}, stdout:\n{}\nstderr:\n{}\n".format(r, rc, a, b)
+        )
         if stdout is not None:
             self.assertEqual(stdout, a)
         if stderr is not None:
@@ -162,12 +167,14 @@ class PatchewTestCase(django.test.LiveServerTestCase):
                                 cwd=repo)
         return repo
 
+
 def parse_args():
     parser = argparse.ArgumentParser()
     parser.add_argument("--debug", "-d", action="store_true",
                         help="Enable debug output, and keep temp dir after done")
     return parser.parse_known_args()
 
+
 def main():
     import unittest
     args, argv = parse_args()
@@ -183,4 +190,3 @@ def main():
     finally:
         if not args.debug:
             shutil.rmtree(RUN_DIR)
-
diff --git a/tests/test_ansi2html.py b/tests/test_ansi2html.py
index e146c3e..16c1d1e 100644
--- a/tests/test_ansi2html.py
+++ b/tests/test_ansi2html.py
@@ -8,6 +8,7 @@ import unittest
 
 from patchew.logviewer import ansi2html, ansi2text, ANSI2TextConverter
 
+
 class ANSI2HTMLTest(unittest.TestCase):
     def assertAnsi(self, test, expected, **kwargs):
         self.assertEqual(''.join(ansi2html(test, **kwargs)),
diff --git a/tests/test_custom_tags.py b/tests/test_custom_tags.py
index c401d0e..49c67e2 100755
--- a/tests/test_custom_tags.py
+++ b/tests/test_custom_tags.py
@@ -12,6 +12,7 @@ from django.template import Context, Template
 from patchew.tags import tail_lines, grep_A, grep_B, grep_C, grep, lines_between
 import unittest
 
+
 class CustomTagsTest(unittest.TestCase):
     def assertTemplate(self, template, expected, **kwargs):
         context = Context(kwargs)
@@ -22,13 +23,13 @@ class CustomTagsTest(unittest.TestCase):
         self.assertTemplate('{{s|grep:"[0-9]"}}', '0\n9', s='0\na\n9')
         self.assertTemplate('{{s|grep_A:"b"}}',
                             'b\nc\nd\ne\n---\nb',
-                             s='a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
+                            s='a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
         self.assertTemplate('{{s|grep_B:"b"}}',
                             'a\nb\n---\nx\ny\nz\nb',
-                             s='a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
+                            s='a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
         self.assertTemplate('{{s|grep_C:"b"}}',
                             'a\nb\nc\nd\ne\n---\nx\ny\nz\nb',
-                             s='a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
+                            s='a\nb\nc\nd\ne\nf\nx\ny\nz\nb')
         self.assertTemplate('{{s|tail_lines:3}}', 'b\nc\nd', s='a\nb\nc\nd')
 
     def test_template_tags(self):
@@ -132,5 +133,6 @@ class CustomTagsTest(unittest.TestCase):
         self.assertEqual(lines_between('a\nb\ncb\nd', 'b', 'c', False), 'b\ncb\nd')
         self.assertEqual(lines_between('a\nb\n\n\na\nb', '.', '^$'), 'a\nb\n\na\nb')
 
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/test_diff.py b/tests/test_diff.py
index 5aaf543..8e37e4f 100755
--- a/tests/test_diff.py
+++ b/tests/test_diff.py
@@ -8,10 +8,8 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-import sys
-import os
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
+from .patchewtest import PatchewTestCase, main
+
 
 class DiffTest(PatchewTestCase):
 
@@ -63,5 +61,6 @@ class DiffTest(PatchewTestCase):
         self.assertEqual(resp3.data['other_versions'][1]['version'], 2)
         self.assertEqual(resp3.data['other_versions'][1]['resource_uri'], resp2.data['resource_uri'])
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_git.py b/tests/test_git.py
index 31e9823..09545df 100755
--- a/tests/test_git.py
+++ b/tests/test_git.py
@@ -8,14 +8,13 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-import sys
-import os
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
 import shutil
-import subprocess
+
 from api.models import Message, Result
 
+from .patchewtest import PatchewTestCase, main
+
+
 class GitTest(PatchewTestCase):
 
     def setUp(self):
@@ -99,7 +98,6 @@ class GitTest(PatchewTestCase):
     def test_rest_git_base(self):
         self.cli_import("0013-foo-patch.mbox.gz")
         self.do_apply()
-        s = Message.objects.series_heads()[0]
         self.cli_import("0014-bar-patch.mbox.gz")
         MESSAGE_ID = '20160628014747.20971-2-famz@redhat.com'
         resp = self.api_client.get('%sseries/%s/' % (self.PROJECT_BASE, MESSAGE_ID))
@@ -141,5 +139,6 @@ class GitTest(PatchewTestCase):
         self.assertEqual(log.status_code, 200)
         self.assertEqual(log.content.decode(), resp.data['log'])
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_import.py b/tests/test_import.py
index 64d8c66..b5fe327 100755
--- a/tests/test_import.py
+++ b/tests/test_import.py
@@ -8,15 +8,14 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-import sys
-import os
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
 import json
+
 from api.models import Message, Project
 
-class ImportTest(PatchewTestCase):
+from .patchewtest import PatchewTestCase, main
+
 
+class ImportTest(PatchewTestCase):
     def setUp(self):
         self.create_superuser()
         self.cli_login()
@@ -97,6 +96,7 @@ class ImportTest(PatchewTestCase):
                          ['[libvirt]  [PATCH v2] vcpupin: add clear feature', subj])
         self.check_cli(["search", "project:Libvirt-python"], stdout=subj)
 
+
 class UnprivilegedImportTest(ImportTest):
     def setUp(self):
         self.create_superuser()
@@ -133,5 +133,6 @@ class UnprivilegedImportTest(ImportTest):
         p.save()
         self.check_cli(["project", "update"])
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_mbox.py b/tests/test_mbox.py
index f003844..d04fa6b 100755
--- a/tests/test_mbox.py
+++ b/tests/test_mbox.py
@@ -8,11 +8,10 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-import os
-import sys
 import mbox
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
+
+from .patchewtest import PatchewTestCase, main
+
 
 class MboxTest(PatchewTestCase):
 
@@ -24,11 +23,11 @@ On 07/25/2017 10:57 AM, Jeff Cody wrote:
 >  redhat/build_configure.sh     | 3 +++
 >  redhat/qemu-kvm.spec.template | 7 +++++++
 >  2 files changed, 10 insertions(+)
-> 
+>
 
 ACK
 
--- 
+--
 Eric Blake, Principal Software Engineer
 Red Hat, Inc.           +1-919-301-3266
 Virtualization:  qemu.org | libvirt.org
@@ -66,10 +65,11 @@ Virtualization:  qemu.org | libvirt.org
                                        {'name': 'Alberto Garcia', 'address': 'berto@igalia.com'},
                                        {'address': 'qemu-block@nongnu.org'},
                                        {'name': 'Max Reitz', 'address': 'mreitz@redhat.com'}],
-                        'mbox':content
+                        'mbox': content
                         }
             msg = mbox.MboxMessage(content).get_json()
         self.assertEqual(msg, expected)
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_message.py b/tests/test_message.py
index 9448aee..419e384 100755
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -10,7 +10,9 @@
 
 import time
 import datetime
-from tests.patchewtest import PatchewTestCase, main
+
+from .patchewtest import PatchewTestCase, main
+
 
 class ProjectTest(PatchewTestCase):
 
@@ -54,5 +56,6 @@ class ProjectTest(PatchewTestCase):
         asctime = message.get_asctime()
         self.assertEqual(asctime, "Sat Oct 22 9:06:04 2016")
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_model.py b/tests/test_model.py
index 1464df2..704c658 100755
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -8,9 +8,11 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-from tests.patchewtest import PatchewTestCase, main
 from api.models import Message
 
+from .patchewtest import PatchewTestCase, main
+
+
 class ImportTest(PatchewTestCase):
 
     def setUp(self):
@@ -136,5 +138,6 @@ mode change 100644 => 100755 tests/qemu-iotests/205
         self.maxDiff = 100000
         self.assertMultiLineEqual(expected.strip(), msg.get_diff_stat())
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_project.py b/tests/test_project.py
index fbc1f0e..9274716 100755
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -8,7 +8,8 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-from tests.patchewtest import PatchewTestCase, main
+from .patchewtest import PatchewTestCase, main
+
 
 class ProjectTest(PatchewTestCase):
 
@@ -77,5 +78,6 @@ class ProjectTest(PatchewTestCase):
         self.assertFalse(p.maintained_by(u1))
         self.assertFalse(p.maintained_by(u2))
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 8c86d9d..4ed9c07 100755
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -8,24 +8,22 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-import sys
-import os
+from collections import OrderedDict
 import json
-import unittest
 
 from django.contrib.auth.models import User
 
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
 from api.models import Message
 from api.rest import AddressSerializer
-from collections import OrderedDict
+
+from .patchewtest import PatchewTestCase, main
 
 try:
     import coreapi
 except ImportError:
     coreapi = None
 
+
 class RestTest(PatchewTestCase):
     def setUp(self):
         self.create_superuser()
@@ -97,15 +95,23 @@ class RestTest(PatchewTestCase):
     def test_update_project_head(self):
         resp = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
                                        self.p.id, '20160628014747.20971-1-famz@redhat.com')
-        self.api_client.login(username=self.user, password=self.password)        
-        resp_before = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
+        self.api_client.login(username=self.user, password=self.password)
+        resp_before = self.api_client.get(
+            self.PROJECT_BASE + "series/" + "20160628014747.20971-1-famz@redhat.com/"
+        )
         data = {
-                "message_ids": ["20160628014747.20971-1-famz@redhat.com"],
-                "old_head": "None",
-                "new_head": "000000"
-                }
-        resp = self.api_client.post(self.PROJECT_BASE + "update_project_head/", data=json.dumps(data), content_type='application/json')
-        resp_after = self.api_client.get(self.PROJECT_BASE + "series/"+ "20160628014747.20971-1-famz@redhat.com/")
+            "message_ids": ["20160628014747.20971-1-famz@redhat.com"],
+            "old_head": "None",
+            "new_head": "000000",
+        }
+        resp = self.api_client.post(
+            self.PROJECT_BASE + "update_project_head/",
+            data=json.dumps(data),
+            content_type='application/json'
+        )
+        resp_after = self.api_client.get(
+            self.PROJECT_BASE + "series/" + "20160628014747.20971-1-famz@redhat.com/"
+        )
         self.assertEquals(resp_before.data['is_merged'], False)
         self.assertEquals(resp.status_code, 200)
         self.assertEquals(resp.data['count'], 1)
@@ -226,10 +232,10 @@ class RestTest(PatchewTestCase):
         self.assertEqual(resp.data['patches'][0]['stripped_subject'], 'crypto: add support for querying parameters for block encryption')
 
     def test_series_list(self):
-        resp1 = self.apply_and_retrieve('0004-multiple-patch-reviewed.mbox.gz',
-                                        self.p.id, '1469192015-16487-1-git-send-email-berrange@redhat.com')
-        resp2 = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
-                                        self.p.id, '20160628014747.20971-1-famz@redhat.com')
+        self.apply_and_retrieve('0004-multiple-patch-reviewed.mbox.gz',
+                                self.p.id, '1469192015-16487-1-git-send-email-berrange@redhat.com')
+        self.apply_and_retrieve('0001-simple-patch.mbox.gz',
+                                self.p.id, '20160628014747.20971-1-famz@redhat.com')
 
         resp = self.api_client.get(self.REST_BASE + 'series/')
         self.assertEqual(resp.data['count'], 2)
@@ -242,7 +248,7 @@ class RestTest(PatchewTestCase):
 
     def test_series_results_list(self):
         resp1 = self.apply_and_retrieve('0001-simple-patch.mbox.gz',
-                                       self.p.id, '20160628014747.20971-1-famz@redhat.com')
+                                        self.p.id, '20160628014747.20971-1-famz@redhat.com')
         resp = self.api_client.get(resp1.data['results'])
         self.assertEqual(resp.data['count'], len(resp.data['results']))
 
@@ -277,20 +283,25 @@ class RestTest(PatchewTestCase):
 
     def test_series_delete(self):
         test_message_id = '1469192015-16487-1-git-send-email-berrange@redhat.com'
-        series = self.apply_and_retrieve('0004-multiple-patch-reviewed.mbox.gz',self.p.id,
-                                         test_message_id)
+        series = self.apply_and_retrieve(
+            '0004-multiple-patch-reviewed.mbox.gz', self.p.id, test_message_id
+        )
         message = series.data['message']
-        resp_before = self.api_client.get(self.REST_BASE + 'projects/' + str(self.p.id)
-                                          + '/series/' + test_message_id + '/')
+        resp_before = self.api_client.get(
+            self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + test_message_id + '/'
+        )
         resp_reply_before = self.api_client.get(message + 'replies/')
-        resp_without_login = self.api_client.delete(self.REST_BASE + 'projects/' + str(self.p.id)
-                                      + '/series/' + test_message_id + '/')
+        resp_without_login = self.api_client.delete(
+            self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + test_message_id + '/'
+        )
         self.api_client.login(username=self.user, password=self.password)
-        resp = self.api_client.delete(self.REST_BASE + 'projects/' + str(self.p.id)
-                                      + '/series/' + test_message_id + '/')
+        resp = self.api_client.delete(
+            self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + test_message_id + '/'
+        )
         self.api_client.logout()
-        resp_after = self.api_client.get(self.REST_BASE + 'projects/' + str(self.p.id)
-                                         + '/series/' + test_message_id + '/')
+        resp_after = self.api_client.get(
+            self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + test_message_id + '/'
+        )
         resp_reply_after = self.api_client.get(message + 'replies/')
 
         self.assertEqual(resp_before.status_code, 200)
@@ -391,7 +402,7 @@ class RestTest(PatchewTestCase):
         dp = self.get_data_path("0023-multiple-project-patch.mbox.gz")
         with open(dp, "r") as f:
             data = f.read()
-        test = self.create_user(username="test", password="userpass", groups=['importers'])
+        self.create_user(username="test", password="userpass", groups=['importers'])
         self.api_client.login(username="test", password="userpass")
         resp = self.api_client.post(self.REST_BASE + "messages/", data, content_type='message/rfc822')
         self.assertEqual(resp.status_code, 201)
@@ -419,19 +430,25 @@ class RestTest(PatchewTestCase):
         self.assertEqual(resp.data, Message.objects.all()[0].get_mbox())
 
     def test_address_serializer(self):
-        data1 = {"name":"Shubham", "address":"shubhamjain7495@gmail.com"}
-        serializer1 = AddressSerializer(data = data1)
+        data1 = {"name": "Shubham", "address": "shubhamjain7495@gmail.com"}
+        serializer1 = AddressSerializer(data=data1)
         valid1 = serializer1.is_valid()
         valid_data1 = serializer1.validated_data
-        data2 = {"name":123, "address":"shubhamjain7495@gmail.com"}
-        serializer2 = AddressSerializer(data = data2)
+        data2 = {"name": 123, "address": "shubhamjain7495@gmail.com"}
+        serializer2 = AddressSerializer(data=data2)
         valid2 = serializer2.is_valid()
         valid_data2 = serializer2.validated_data
 
-        self.assertEqual(valid1,True)
-        self.assertEqual(valid_data1,OrderedDict([('name', 'Shubham'), ('address', 'shubhamjain7495@gmail.com')]))
-        self.assertEqual(valid2,True)
-        self.assertEqual(valid_data2,OrderedDict([('name', '123'), ('address', 'shubhamjain7495@gmail.com')]))
+        self.assertEqual(valid1, True)
+        self.assertEqual(
+            valid_data1,
+            OrderedDict([('name', 'Shubham'), ('address', 'shubhamjain7495@gmail.com')])
+        )
+        self.assertEqual(valid2, True)
+        self.assertEqual(
+            valid_data2,
+            OrderedDict([('name', '123'), ('address', 'shubhamjain7495@gmail.com')])
+        )
 
     def test_message_replies(self):
         series = self.apply_and_retrieve('0004-multiple-patch-reviewed.mbox.gz',
@@ -453,5 +470,6 @@ class RestTest(PatchewTestCase):
         resp = self.api_client.get(self.REST_BASE + 'schema/')
         self.assertEqual(resp.status_code, 200)
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_tags.py b/tests/test_tags.py
index 075c497..1be2a7f 100755
--- a/tests/test_tags.py
+++ b/tests/test_tags.py
@@ -8,15 +8,14 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
-import sys
-import os
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
 import email
 import email.parser
 import email.policy
 from mbox import decode_payload
 
+from .patchewtest import PatchewTestCase, main
+
+
 class ImportTest(PatchewTestCase):
 
     def setUp(self):
@@ -63,5 +62,6 @@ class ImportTest(PatchewTestCase):
         self.assertIn('SynICState *synic = get_synic(cs);', payload)
         self.assertIn('Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>', payload)
 
+
 if __name__ == '__main__':
     main()
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 6f2808c..a5c22e1 100755
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -9,13 +9,13 @@
 # http://opensource.org/licenses/MIT.
 
 import abc
-import sys
-import os
 import subprocess
-sys.path.append(os.path.dirname(__file__))
-from tests.patchewtest import PatchewTestCase, main
+
 from api.models import Message, Result
 
+from .patchewtest import PatchewTestCase, main
+
+
 def create_test(project, name, requirements="", script="#!/bin/bash\ntrue"):
     prefix = "testing.tests." + name + "."
     project.set_property(prefix + "timeout", 3600)
@@ -23,6 +23,7 @@ def create_test(project, name, requirements="", script="#!/bin/bash\ntrue"):
     project.set_property(prefix + "script", script)
     project.set_property(prefix + "requirements", requirements)
 
+
 class TestingTestCase(PatchewTestCase, metaclass=abc.ABCMeta):
 
     def setUp(self):
@@ -36,7 +37,7 @@ class TestingTestCase(PatchewTestCase, metaclass=abc.ABCMeta):
     def modify_test_result(self, obj, **kwargs):
         try:
             r = obj.results.get(name='testing.a')
-        except:
+        except Exception:
             r = obj.create_result(name='testing.a')
             if 'status' not in kwargs:
                 kwargs['status'] = Result.PENDING
@@ -52,28 +53,30 @@ class TestingTestCase(PatchewTestCase, metaclass=abc.ABCMeta):
             r.save()
 
     def _do_testing_done(self, obj, **kwargs):
-        if not 'status' in kwargs:
+        if 'status' not in kwargs:
             kwargs['status'] = Result.SUCCESS
         self.modify_test_result(obj, **kwargs)
         obj.set_property("testing.done", True)
 
     def do_testing_report(self, **report):
         self.api_login()
-        r = self.api_call("testing-get",
-                           project="QEMU",
-                           tester="dummy tester",
-                           capabilities=[])
+        r = self.api_call(
+            "testing-get",
+            project="QEMU",
+            tester="dummy tester",
+            capabilities=[],
+        )
         report['project'] = r["project"]
         report['identity'] = r["identity"]
         report['test'] = r["test"]["name"]
         report['tester'] = 'dummy_tester'
         report['head'] = r["head"]
         report['base'] = r["base"]
-        if not 'passed' in report:
+        if 'passed' not in report:
             report['passed'] = True
-        if not 'log' in report:
+        if 'log' not in report:
             report['log'] = None
-        if not 'is_timeout' in report:
+        if 'is_timeout' not in report:
             report['is_timeout'] = False
 
         self.api_call("testing-report", **report)
@@ -150,6 +153,7 @@ class TestingTestCase(PatchewTestCase, metaclass=abc.ABCMeta):
         self.assertEquals(log.status_code, 200)
         self.assertEquals(log.content, b'sorry no good')
 
+
 class MessageTestingTest(TestingTestCase):
 
     def setUp(self):
@@ -170,15 +174,19 @@ class MessageTestingTest(TestingTestCase):
         return r
 
     def get_test_result(self, test_name):
-        return self.api_client.get('%sseries/%s/results/testing.%s/' % (
-                                       self.PROJECT_BASE, self.msg.message_id, test_name))
+        return self.api_client.get(
+            '%sseries/%s/results/testing.%s/' % (
+                self.PROJECT_BASE,
+                self.msg.message_id,
+                test_name
+            ))
 
     def test_testing_ready(self):
         self.assertEqual(self.msg.results.filter(name='testing.a').first().status,
                          Result.PENDING)
 
-class ProjectTestingTest(TestingTestCase):
 
+class ProjectTestingTest(TestingTestCase):
     def setUp(self):
         super(ProjectTestingTest, self).setUp()
         self.p.set_property("git.head", "5678")
@@ -193,11 +201,12 @@ class ProjectTestingTest(TestingTestCase):
         return r
 
     def get_test_result(self, test_name):
-        return self.api_client.get('%sresults/testing.%s/' % (
-                                       self.PROJECT_BASE, test_name))
+        return self.api_client.get(
+            '%sresults/testing.%s/' % (self.PROJECT_BASE, test_name)
+        )
 
-class TesterTest(PatchewTestCase):
 
+class TesterTest(PatchewTestCase):
     def setUp(self):
         self.create_superuser()
 
@@ -227,8 +236,9 @@ class TesterTest(PatchewTestCase):
         self.update_head(self.p2)
         self.update_head(self.p3)
         self.update_head(self.p4)
-        base = subprocess.check_output(["git", "rev-parse", "HEAD~1"],
-                                       cwd=self.repo).decode()
+        subprocess.check_output(
+            ["git", "rev-parse", "HEAD~1"],
+            cwd=self.repo).decode()
         subprocess.check_output(["git", "tag", "test"], cwd=self.repo)
 
     def add_file_and_commit(self, f):
@@ -314,8 +324,8 @@ class TesterTest(PatchewTestCase):
         self.assertIn("Nothing to test", out)
         self.cli_logout()
 
-class TestingResetTest(PatchewTestCase):
 
+class TestingResetTest(PatchewTestCase):
     def setUp(self):
         self.create_superuser()
 
@@ -364,8 +374,8 @@ class TestingResetTest(PatchewTestCase):
                                   "testing.c": Result.PENDING})
         self.assertFalse(msg.get_property("testing.done"))
 
-class TestingDisableTest(PatchewTestCase):
 
+class TestingDisableTest(PatchewTestCase):
     def setUp(self):
         self.create_superuser()
 
@@ -383,8 +393,10 @@ class TestingDisableTest(PatchewTestCase):
         self.assertNotIn("Project: QEMU\n", out)
         self.cli_logout()
 
+
 # do not run tests on the abstract class
 del TestingTestCase
 
+
 if __name__ == '__main__':
     main()
-- 
2.19.2

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel