#3 Make the tests flake8 valid and enforce it in tox
Merged 3 years ago by nphilipp. Opened 3 years ago by pingou.

file modified
+2 -2
@@ -5,12 +5,12 @@ 

  

  class TestDebugToddler:

      def test_accepts_topic(self):

-         assert toddlers.plugins.debug.DebugToddler.accepts_topic("foo.bar") == True

+         assert toddlers.plugins.debug.DebugToddler.accepts_topic("foo.bar")

  

      def test_process(self):

          msg = fedora_messaging.api.Message()

          msg.id = 123

          msg.topic = "toddlers.test.topic"

          assert (

-             toddlers.plugins.debug.DebugToddler.process(config={}, message=msg) == None

+             toddlers.plugins.debug.DebugToddler.process(config={}, message=msg) is None

          )

@@ -9,7 +9,7 @@ 

  

  class TestFlagCIPRToddler:

      def test_accepts_topic_invalid(self):

-         assert toddlers.plugins.flag_ci_pr.FlagCIPR.accepts_topic("foo.bar") == False

+         assert toddlers.plugins.flag_ci_pr.FlagCIPR.accepts_topic("foo.bar") is False

  

      @pytest.mark.parametrize(

          "topic",
@@ -26,14 +26,14 @@ 

          ],

      )

      def test_accepts_topic_valid(self, topic):

-         assert toddlers.plugins.flag_ci_pr.FlagCIPR.accepts_topic(topic) == True

+         assert toddlers.plugins.flag_ci_pr.FlagCIPR.accepts_topic(topic)

  

      def test_process_invalid(self):

          msg = fedora_messaging.api.Message()

          msg.id = 123

          msg.topic = "toddlers.test.topic"

          assert (

-             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) == None

+             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) is None

          )

  

      def test_process_invalid_status(self, caplog):
@@ -42,7 +42,7 @@ 

          msg.id = 123

          msg.topic = "org.centos.stg.ci.dist-git-pr.test.invalid"

          assert (

-             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) == None

+             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) is None

          )

          assert (

              caplog.records[-1].message
@@ -55,7 +55,7 @@ 

          msg.id = 123

          msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete"

          assert (

-             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) == None

+             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) is None

          )

          assert caplog.records[-1].message == "Unsupported msg version, ignoring"

  
@@ -64,9 +64,9 @@ 

          msg = fedora_messaging.api.Message()

          msg.id = 123

          msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete"

-         msg.body = {"version": "0.2.1", "test": {"result": "invalid",}}

+         msg.body = {"version": "0.2.1", "test": {"result": "invalid"}}

          assert (

-             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) == None

+             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) is None

          )

          assert (

              caplog.records[-1].message
@@ -80,15 +80,16 @@ 

          msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete"

          msg.body = {

              "version": "0.2.1",

-             "test": {"result": "passed",},

-             "artifact": {"commit_hash": "abcdefghijklmnopqrst",},

+             "test": {"result": "passed"},

+             "artifact": {"commit_hash": "abcdefghijklmnopqrst"},

          }

          assert (

-             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) == None

+             toddlers.plugins.flag_ci_pr.FlagCIPR.process(config={}, message=msg) is None

          )

          assert (

              caplog.records[-1].message

-             == "Invalid message: {'commit_hash': 'abcdefghijklmnopqrst'}, could not extract the PR id from it"

+             == "Invalid message: {'commit_hash': 'abcdefghijklmnopqrst'}, could not extract "

+             "the PR id from it"

          )

  

      @patch("toddlers.plugins.flag_ci_pr.requests_session")
@@ -102,13 +103,13 @@ 

          msg.topic = "org.centos.stg.ci.dist-git-pr.test.running"

          msg.body = {

              "version": "0.2.1",

-             "test": {"result": "passed",},

+             "test": {"result": "passed"},

              "artifact": {

                  "id": 456,

                  "commit_hash": "abcdefghijklmnopqrst",

                  "repository": "namespace/name",

              },

-             "run": {"url": "https://example.com/testing",},

+             "run": {"url": "https://example.com/testing"},

          }

          config = {

              "pagure_token_seed": "example_seed",
@@ -135,13 +136,13 @@ 

          msg.topic = "org.centos.stg.ci.dist-git-pr.test.error"

          msg.body = {

              "version": "0.2.1",

-             "test": {"result": "passed",},

+             "test": {"result": "passed"},

              "artifact": {

                  "id": 456,

                  "commit_hash": "abcdefghijklmnopqrst",

                  "repository": "https://host.c/namespace/name",

              },

-             "run": {"url": "https://example.com/testing",},

+             "run": {"url": "https://example.com/testing"},

          }

          config = {

              "pagure_token_seed": "example_seed",
@@ -151,7 +152,7 @@ 

  

          assert (

              toddlers.plugins.flag_ci_pr.FlagCIPR.process(config=config, message=msg)

-             == None

+             is None

          )

          assert (

              caplog.records[-3].message == "Request to https://pagure.io returned: 200"

@@ -11,7 +11,7 @@ 

      def test_accepts_topic_invalid(self):

          assert (

              toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic("foo.bar")

-             == False

+             is False

          )

  

      @pytest.mark.parametrize(
@@ -23,10 +23,7 @@ 

          ],

      )

      def test_accepts_topic_valid(self, topic):

-         assert (

-             toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic(topic)

-             == True

-         )

+         assert toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic(topic)

  

      def test_process_containerbuild(self, caplog):

          caplog.set_level(logging.INFO)
@@ -38,7 +35,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config={}, message=msg

              )

-             == None

+             is None

          )

          assert caplog.records[-1].message == "Skipping container build"

  
@@ -52,7 +49,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config={}, message=msg

              )

-             == None

+             is None

          )

          assert caplog.records[-1].message == "Skipping MBS builds"

  
@@ -69,7 +66,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config={}, message=msg

              )

-             == None

+             is None

          )

          assert caplog.records[-1].message == "Ignoring secondary arch task..."

  
@@ -87,7 +84,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config={}, message=msg

              )

-             == None

+             is None

          )

          assert (

              caplog.records[-1].message
@@ -114,7 +111,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config=config, message=msg

              )

-             == None

+             is None

          )

          assert (

              caplog.records[-1].message
@@ -143,7 +140,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config=config, message=msg

              )

-             == None

+             is None

          )

          assert caplog.records[-1].message == "No # in the git_url: foobar"

  
@@ -158,7 +155,8 @@ 

              return_value={

                  "extra": {

                      "source": {

-                         "original_url": "https://src.fedoraproject.org/rpms/guake.git#commit_hash123"

+                         "original_url": "https://src.fedoraproject.org/rpms/"

+                         "guake.git#commit_hash123"

                      }

                  }

              }
@@ -188,7 +186,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config=config, message=msg

              )

-             == None

+             is None

          )

          assert (

              caplog.records[-1].message
@@ -206,7 +204,8 @@ 

              return_value={

                  "extra": {

                      "source": {

-                         "original_url": "https://src.fedoraproject.org/rpms/guake.git#commit_hash123"

+                         "original_url": "https://src.fedoraproject.org/rpms/"

+                         "guake.git#commit_hash123"

                      }

                  }

              }
@@ -236,7 +235,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config=config, message=msg

              )

-             == None

+             is None

          )

          assert (

              caplog.records[-1].message
@@ -254,7 +253,8 @@ 

              return_value={

                  "extra": {

                      "source": {

-                         "original_url": "https://src.fedoraproject.org/rpms/guake.git#commit_hash123"

+                         "original_url": "https://src.fedoraproject.org/rpms/"

+                         "guake.git#commit_hash123"

                      }

                  }

              }
@@ -283,7 +283,7 @@ 

              toddlers.plugins.flag_commit_build.FlagCommitBuild.process(

                  config=config, message=msg

              )

-             == None

+             is None

          )

          assert (

              caplog.records[-3].message

file modified
+2 -2
@@ -9,7 +9,7 @@ 

          assert toddlers.base.ToddlerBase.amqp_topics.fget() == []

  

      def test_accepts_topic(self):

-         assert toddlers.base.ToddlerBase.accepts_topic("foo.bar") == None

+         assert toddlers.base.ToddlerBase.accepts_topic("foo.bar") is None

  

      def test_process(self):

-         assert toddlers.base.ToddlerBase.process(config={}, message={}) == None

+         assert toddlers.base.ToddlerBase.process(config={}, message={}) is None

file modified
+1 -1
@@ -23,4 +23,4 @@ 

  deps =

      flake8

  commands =

-     flake8 toddlers/

+     flake8 .

no initial comment

rebased onto 03c7a53

3 years ago

rebased onto 5ac66b3a39dde15a0f5fe5b273056c0e50f259a5

3 years ago

Why not just assert toddlers.plugins.debug.DebugToddler.accepts_topic("foo.bar") (same below)? Going by the idiom here...: https://docs.python.org/3/library/stdtypes.html#truth-value-testing

Metadata Update from @nphilipp:
- Request assigned

3 years ago

I was thinking explicit > implicit but I'm fine changing this

rebased onto 900cf07fdba99f5475f03fede758e31fabda99ac

3 years ago

rebased onto 5662932162eb4227445ef563b8f8f6d0ca2588c3

3 years ago

rebased onto da91803607e310d940a02a58854703f7cb816257

3 years ago

rebased onto 7af467e

3 years ago

Pull-Request has been merged by nphilipp

3 years ago