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:
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
)

View file

@ -9,7 +9,7 @@ import fedora_messaging.api
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 @@ class TestFlagCIPRToddler:
],
)
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 @@ class TestFlagCIPRToddler:
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 @@ class TestFlagCIPRToddler:
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 @@ class TestFlagCIPRToddler:
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 @@ class TestFlagCIPRToddler:
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 @@ class TestFlagCIPRToddler:
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 @@ class TestFlagCIPRToddler:
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 @@ class TestFlagCIPRToddler:
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"

View file

@ -11,7 +11,7 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
],
)
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 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config={}, message=msg
)
== None
is None
)
assert (
caplog.records[-1].message
@ -114,7 +111,7 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg
)
== None
is None
)
assert (
caplog.records[-1].message
@ -143,7 +140,7 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg
)
== None
is None
)
assert (
caplog.records[-1].message
@ -206,7 +204,8 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg
)
== None
is None
)
assert (
caplog.records[-1].message
@ -254,7 +253,8 @@ class TestFlagCommitBuildToddler:
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 @@ class TestFlagCommitBuildToddler:
toddlers.plugins.flag_commit_build.FlagCommitBuild.process(
config=config, message=msg
)
== None
is None
)
assert (
caplog.records[-3].message

View file

@ -9,7 +9,7 @@ class TestToddlerBase:
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

View file

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