Make the tests flake8 valid and enforce it in tox

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2020-06-26 15:45:09 +02:00 committed by pingou
parent 08a76aefab
commit 7af467ef1d
5 changed files with 39 additions and 38 deletions

View file

@ -5,12 +5,12 @@ import fedora_messaging.api
class TestDebugToddler: class TestDebugToddler:
def test_accepts_topic(self): 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): def test_process(self):
msg = fedora_messaging.api.Message() msg = fedora_messaging.api.Message()
msg.id = 123 msg.id = 123
msg.topic = "toddlers.test.topic" msg.topic = "toddlers.test.topic"
assert ( assert (
toddlers.plugins.debug.DebugToddler.process(config={}, message=msg) == None toddlers.plugins.debug.DebugToddler.process(config={}, message=msg) is None
) )

View file

@ -9,7 +9,7 @@ import fedora_messaging.api
class TestFlagCIPRToddler: class TestFlagCIPRToddler:
def test_accepts_topic_invalid(self): 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( @pytest.mark.parametrize(
"topic", "topic",
@ -26,14 +26,14 @@ class TestFlagCIPRToddler:
], ],
) )
def test_accepts_topic_valid(self, topic): 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): def test_process_invalid(self):
msg = fedora_messaging.api.Message() msg = fedora_messaging.api.Message()
msg.id = 123 msg.id = 123
msg.topic = "toddlers.test.topic" msg.topic = "toddlers.test.topic"
assert ( 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): def test_process_invalid_status(self, caplog):
@ -42,7 +42,7 @@ class TestFlagCIPRToddler:
msg.id = 123 msg.id = 123
msg.topic = "org.centos.stg.ci.dist-git-pr.test.invalid" msg.topic = "org.centos.stg.ci.dist-git-pr.test.invalid"
assert ( 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 ( assert (
caplog.records[-1].message caplog.records[-1].message
@ -55,7 +55,7 @@ class TestFlagCIPRToddler:
msg.id = 123 msg.id = 123
msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete" msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete"
assert ( 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" assert caplog.records[-1].message == "Unsupported msg version, ignoring"
@ -64,9 +64,9 @@ class TestFlagCIPRToddler:
msg = fedora_messaging.api.Message() msg = fedora_messaging.api.Message()
msg.id = 123 msg.id = 123
msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete" 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 ( 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 ( assert (
caplog.records[-1].message caplog.records[-1].message
@ -80,15 +80,16 @@ class TestFlagCIPRToddler:
msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete" msg.topic = "org.centos.stg.ci.dist-git-pr.test.complete"
msg.body = { msg.body = {
"version": "0.2.1", "version": "0.2.1",
"test": {"result": "passed",}, "test": {"result": "passed"},
"artifact": {"commit_hash": "abcdefghijklmnopqrst",}, "artifact": {"commit_hash": "abcdefghijklmnopqrst"},
} }
assert ( 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 ( assert (
caplog.records[-1].message 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") @patch("toddlers.plugins.flag_ci_pr.requests_session")
@ -102,13 +103,13 @@ class TestFlagCIPRToddler:
msg.topic = "org.centos.stg.ci.dist-git-pr.test.running" msg.topic = "org.centos.stg.ci.dist-git-pr.test.running"
msg.body = { msg.body = {
"version": "0.2.1", "version": "0.2.1",
"test": {"result": "passed",}, "test": {"result": "passed"},
"artifact": { "artifact": {
"id": 456, "id": 456,
"commit_hash": "abcdefghijklmnopqrst", "commit_hash": "abcdefghijklmnopqrst",
"repository": "namespace/name", "repository": "namespace/name",
}, },
"run": {"url": "https://example.com/testing",}, "run": {"url": "https://example.com/testing"},
} }
config = { config = {
"pagure_token_seed": "example_seed", "pagure_token_seed": "example_seed",
@ -135,13 +136,13 @@ class TestFlagCIPRToddler:
msg.topic = "org.centos.stg.ci.dist-git-pr.test.error" msg.topic = "org.centos.stg.ci.dist-git-pr.test.error"
msg.body = { msg.body = {
"version": "0.2.1", "version": "0.2.1",
"test": {"result": "passed",}, "test": {"result": "passed"},
"artifact": { "artifact": {
"id": 456, "id": 456,
"commit_hash": "abcdefghijklmnopqrst", "commit_hash": "abcdefghijklmnopqrst",
"repository": "https://host.c/namespace/name", "repository": "https://host.c/namespace/name",
}, },
"run": {"url": "https://example.com/testing",}, "run": {"url": "https://example.com/testing"},
} }
config = { config = {
"pagure_token_seed": "example_seed", "pagure_token_seed": "example_seed",
@ -151,7 +152,7 @@ class TestFlagCIPRToddler:
assert ( assert (
toddlers.plugins.flag_ci_pr.FlagCIPR.process(config=config, message=msg) toddlers.plugins.flag_ci_pr.FlagCIPR.process(config=config, message=msg)
== None is None
) )
assert ( assert (
caplog.records[-3].message == "Request to https://pagure.io returned: 200" caplog.records[-3].message == "Request to https://pagure.io returned: 200"

View file

@ -11,7 +11,7 @@ class TestFlagCommitBuildToddler:
def test_accepts_topic_invalid(self): def test_accepts_topic_invalid(self):
assert ( assert (
toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic("foo.bar") toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic("foo.bar")
== False is False
) )
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -23,10 +23,7 @@ class TestFlagCommitBuildToddler:
], ],
) )
def test_accepts_topic_valid(self, topic): def test_accepts_topic_valid(self, topic):
assert ( assert toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic(topic)
toddlers.plugins.flag_commit_build.FlagCommitBuild.accepts_topic(topic)
== True
)
def test_process_containerbuild(self, caplog): def test_process_containerbuild(self, caplog):
caplog.set_level(logging.INFO) caplog.set_level(logging.INFO)
@ -38,7 +35,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config={}, message=msg config={}, message=msg
) )
== None is None
) )
assert caplog.records[-1].message == "Skipping container build" assert caplog.records[-1].message == "Skipping container build"
@ -52,7 +49,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config={}, message=msg config={}, message=msg
) )
== None is None
) )
assert caplog.records[-1].message == "Skipping MBS builds" assert caplog.records[-1].message == "Skipping MBS builds"
@ -69,7 +66,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config={}, message=msg config={}, message=msg
) )
== None is None
) )
assert caplog.records[-1].message == "Ignoring secondary arch task..." assert caplog.records[-1].message == "Ignoring secondary arch task..."
@ -87,7 +84,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config={}, message=msg config={}, message=msg
) )
== None is None
) )
assert ( assert (
caplog.records[-1].message caplog.records[-1].message
@ -114,7 +111,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg config=config, message=msg
) )
== None is None
) )
assert ( assert (
caplog.records[-1].message caplog.records[-1].message
@ -143,7 +140,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg config=config, message=msg
) )
== None is None
) )
assert caplog.records[-1].message == "No # in the git_url: foobar" assert caplog.records[-1].message == "No # in the git_url: foobar"
@ -158,7 +155,8 @@ class TestFlagCommitBuildToddler:
return_value={ return_value={
"extra": { "extra": {
"source": { "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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg config=config, message=msg
) )
== None is None
) )
assert ( assert (
caplog.records[-1].message caplog.records[-1].message
@ -206,7 +204,8 @@ class TestFlagCommitBuildToddler:
return_value={ return_value={
"extra": { "extra": {
"source": { "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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg config=config, message=msg
) )
== None is None
) )
assert ( assert (
caplog.records[-1].message caplog.records[-1].message
@ -254,7 +253,8 @@ class TestFlagCommitBuildToddler:
return_value={ return_value={
"extra": { "extra": {
"source": { "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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process( toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg config=config, message=msg
) )
== None is None
) )
assert ( assert (
caplog.records[-3].message caplog.records[-3].message

View file

@ -9,7 +9,7 @@ class TestToddlerBase:
assert toddlers.base.ToddlerBase.amqp_topics.fget() == [] assert toddlers.base.ToddlerBase.amqp_topics.fget() == []
def test_accepts_topic(self): 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): def test_process(self):
assert toddlers.base.ToddlerBase.process(config={}, message={}) == None assert toddlers.base.ToddlerBase.process(config={}, message={}) is None

View file

@ -23,4 +23,4 @@ commands =
deps = deps =
flake8 flake8
commands = commands =
flake8 toddlers/ flake8 .