Skip to content

Commit

Permalink
use fixtures in test_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeldmann committed Sep 5, 2022
1 parent 2116764 commit 360a810
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions tests/core/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
import pytest
from organize.core import should_execute


def test_no_tags_given():
assert should_execute(rule_tags=None, tags=None, skip_tags=None)
assert should_execute(rule_tags=["tag"], tags=None, skip_tags=None)
assert should_execute(rule_tags=["tag", "tag2"], tags=None, skip_tags=None)


def test_run_tagged():
assert not should_execute(rule_tags=None, tags=["tag"], skip_tags=None)
assert should_execute(rule_tags=["tag"], tags=["tag"], skip_tags=None)
assert should_execute(rule_tags=["tag", "tag2"], tags=["tag"], skip_tags=None)
assert not should_execute(rule_tags=["foo", "bar"], tags=["tag"], skip_tags=None)
assert not should_execute(rule_tags=["taggity"], tags=["tag"], skip_tags=None)


def test_skip():
assert should_execute(rule_tags=None, tags=None, skip_tags=["tag"])
assert should_execute(rule_tags=["tag"], tags=None, skip_tags=["asd"])
assert not should_execute(rule_tags=["tag"], tags=None, skip_tags=["tag"])
assert not should_execute(rule_tags=["tag", "tag2"], tags=None, skip_tags=["tag"])


def test_combination():
assert not should_execute(rule_tags=None, tags=["tag"], skip_tags=["foo"])
assert not should_execute(rule_tags=["foo", "tag"], tags=["tag"], skip_tags=["foo"])


def test_always():
assert should_execute(rule_tags=["always"], tags=["debug", "test"], skip_tags=None)
assert should_execute(rule_tags=["always", "tag"], tags=None, skip_tags=["tag"])
# skip only if specifically requested
assert not should_execute(
rule_tags=["always", "tag"], tags=None, skip_tags=["always"]
)


def test_never():
assert not should_execute(rule_tags=["never"], tags=None, skip_tags=None)
assert not should_execute(rule_tags=["never", "tag"], tags=["tag"], skip_tags=None)
# run only if specifically requested
assert should_execute(rule_tags=["never", "tag"], tags=["never"], skip_tags=None)
@pytest.mark.parametrize(
"result, rule_tags, tags, skip_tags",
(
# no tags given
(True, None, None, None),
(True, ["tag"], None, None),
(True, ["tag", "tag2"], None, None),
# run tagged
(False, None, ["tag"], None),
(True, ["tag"], ["tag"], None),
(True, ["tag", "tag2"], ["tag"], None),
(False, ["foo", "bar"], ["tag"], None),
(False, ["taggity"], ["tag"], None),
# skip
(True, None, None, ["tag"]),
(True, ["tag"], None, ["asd"]),
(False, ["tag"], None, ["tag"]),
(False, ["tag", "tag2"], None, ["tag"]),
# combination
(False, None, ["tag"], ["foo"]),
(False, ["foo", "tag"], ["tag"], ["foo"]),
# always
(True, ["always"], ["debug", "test"], None),
(True, ["always", "tag"], None, ["tag"]),
# skip only if specifically requested
(False, ["always", "tag"], None, ["always"]),
# never
(False, ["never"], None, None),
(False, ["never", "tag"], ["tag"], None),
# run only if specifically requested
(True, ["never", "tag"], ["never"], None),
),
)
def test_tags(result, rule_tags, tags, skip_tags):
assert should_execute(rule_tags=rule_tags, tags=tags, skip_tags=skip_tags) == result

0 comments on commit 360a810

Please sign in to comment.