Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Oct 25, 2023
1 parent 806ba64 commit 3b40f5a
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 35 deletions.
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
default_install_hook_types:
- pre-commit
- pre-push
- commit-msg

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# - id: check-yaml
- id: end-of-file-fixer
stages: [pre-commit]
- id: trailing-whitespace
stages: [pre-commit]
- id: debug-statements
stages: [pre-push]

# ## Isort
# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort
# name: isort
# stages: [pre-commit]

# ## Black
# - repo: https://github.com/psf/black
# rev: 23.3.0
# hooks:
# - id: black
# stages: [pre-commit]

# ## Ruff
# - repo: https://github.com/charliermarsh/ruff-pre-commit
# rev: v0.0.260
# hooks:
# - id: ruff
# stages: [pre-commit]
28 changes: 12 additions & 16 deletions ckanext/or_facet/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ class TestExtraOrs(object):
def test_base_case(self):
extras = {
"ext_a": 1,
plugin._extra_or_prefix + 'tags': 'on',
plugin._extra_or_prefix + 'groups': 'off',
}
assert plugin._get_extra_ors_state(extras) == {
'tags': True, "groups": False
plugin._extra_or_prefix + "tags": "on",
plugin._extra_or_prefix + "groups": "off",
}
assert plugin._get_extra_ors_state(extras) == {"tags": True, "groups": False}


class TestSplit(object):
@pytest.mark.parametrize(
"fq, field, expected",
[
('tags:"Structural Framework"', "tags",
('{!q.op=OR tag=orFqtags}tags:"Structural Framework"', "")),
(
'tags:"Structural Framework"',
"tags",
('{!q.op=OR tag=orFqtags}tags:"Structural Framework"', ""),
),
("organization:123", "tags", (None, "organization:123")),
("", "tags", (None, "")),
("x:1", "x", (_orPrefix("x") + "x:1", "")),
Expand All @@ -70,7 +71,6 @@ class TestSplit(object):
"z-z",
(_orPrefix("z-z") + "z-z:c-c", "x-x:a-a y-y:b-b"),
),
],
)
def test_split(self, fq, field, expected):
Expand All @@ -80,7 +80,7 @@ def test_split(self, fq, field, expected):
@pytest.mark.usefixtures("clean_db", "clean_index")
class TestPlugin(object):
@pytest.mark.ckan_config("or_facet.or_facets", "tags res_format")
def test_search_with_two_ors(self):
def test_search_with_two_ors(self, organization):
expected_tags = {"bye": 1, "hello": 1, "world": 2}
expected_formats = {"JSON": 1, "HTML": 1, "CSV": 2}

Expand Down Expand Up @@ -131,7 +131,7 @@ def test_search_with_one_or_and_one_extra_or(self):
fq="tags:{}".format(tag),
**{
"facet.field": '["tags"]',
plugin._extra_or_prefix + 'res_format': 'on'
plugin._extra_or_prefix + "res_format": "on",
}
)
assert result["count"] == count
Expand All @@ -143,7 +143,7 @@ def test_search_with_one_or_and_one_extra_or(self):
fq="res_format:{}".format(fmt),
**{
"facet.field": '["res_format"]',
plugin._extra_or_prefix + 'res_format': 'on'
plugin._extra_or_prefix + "res_format": "on",
}
)
assert result["count"] == count
Expand All @@ -166,7 +166,6 @@ def test_search_with_one_or(self):
assert result["facets"]["tags"] == expected_tags

def test_search_without_ors(self):

factories.Dataset(tags=[{"name": "hello"}, {"name": "world"}])
factories.Dataset(tags=[{"name": "bye"}, {"name": "world"}])

Expand All @@ -180,10 +179,7 @@ def test_search_without_ors(self):
assert result["facets"]["tags"] == {"hello": 1, "world": 1}

result = helpers.call_action(
"package_search",
fl="id,tags",
fq="tags:bye",
**{"facet.field": '["tags"]'}
"package_search", fl="id,tags", fq="tags:bye", **{"facet.field": '["tags"]'}
)
assert result["count"] == 1
assert result["facets"]["tags"] == {"bye": 1, "world": 1}
Expand Down
136 changes: 127 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,127 @@
[black]
line-length = 79
[tool.towncrier]
issue_format = ""
directory = "changes"
package = "ckanext.or_facet"
package_dir = "ckanext"
filename = "CHANGELOG.rst"
name = "ckanext-or-facet"
[tool.black]
# line-length = 88
# preview = true

[tool.ruff]
target-version = "py38"
select = [
# "B", # likely bugs and design problems
# "BLE", # do not catch blind exception
# "C40", # better list/set/dict comprehensions
# "C90", # check McCabe complexity
# "COM", # trailing commas
"E", # pycodestyle error
# "W", # pycodestyle warning
"F", # pyflakes
# "G", # format strings for logging statements
# "N", # naming conventions
# "PL", # pylint
# "PT", # pytest style
# "PIE", # misc lints
# "Q", # preferred quoting style
# "RET", # improvements for return statements
# "RSE", # improvements for rise statements
# "S", # security testing
# "SIM", # simplify code
# "T10", # debugging statements
# "T20", # print statements
# "TID", # tidier imports
# "TRY", # better exceptions
# "UP", # upgrade syntax for newer versions of the language
]
ignore = [
"E712", # comparison to bool: violated by SQLAlchemy filters
"PT004", # fixture does not return anything, add leading underscore: violated by clean_db
"PLC1901", # simplify comparison to empty string: violated by SQLAlchemy filters
]

[tool.ruff.per-file-ignores]
"ckanext/or_facet/tests*" = ["S", "PL"]

[tool.isort]
known_ckan = "ckan"
known_ckanext = "ckanext"
known_self = "ckanext.or_facet"
sections = "FUTURE,STDLIB,FIRSTPARTY,THIRDPARTY,CKAN,CKANEXT,SELF,LOCALFOLDER"
profile = "black"

[tool.pytest.ini_options]
addopts = "--ckan-ini test.ini"
filterwarnings = [
"ignore::sqlalchemy.exc.SADeprecationWarning",
"ignore::sqlalchemy.exc.SAWarning",
"ignore::DeprecationWarning",
]

[tool.pyright]
pythonVersion = "3.8"
include = ["ckanext"]
exclude = [
"**/test*",
"**/migration",
]
strict = []

strictParameterNoneValue = true

# Check the meaning of rules here
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md
reportFunctionMemberAccess = true # non-standard member accesses for functions
reportMissingImports = true
reportMissingModuleSource = true
reportMissingTypeStubs = false
reportImportCycles = true
reportUnusedImport = true
reportUnusedClass = true
reportUnusedFunction = true
reportUnusedVariable = true
reportDuplicateImport = true
reportOptionalSubscript = true
reportOptionalMemberAccess = true
reportOptionalCall = true
reportOptionalIterable = true
reportOptionalContextManager = true
reportOptionalOperand = true
reportTypedDictNotRequiredAccess = false # Context won't work with this rule
reportConstantRedefinition = true
reportIncompatibleMethodOverride = true
reportIncompatibleVariableOverride = true
reportOverlappingOverload = true
reportUntypedFunctionDecorator = false
reportUnknownParameterType = true
reportUnknownArgumentType = false
reportUnknownLambdaType = false
reportUnknownMemberType = false
reportMissingTypeArgument = true
reportInvalidTypeVarUse = true
reportCallInDefaultInitializer = true
reportUnknownVariableType = true
reportUntypedBaseClass = true
reportUnnecessaryIsInstance = true
reportUnnecessaryCast = true
reportUnnecessaryComparison = true
reportAssertAlwaysTrue = true
reportSelfClsParameterName = true
reportUnusedCallResult = false # allow function calls for side-effect only
useLibraryCodeForTypes = true
reportGeneralTypeIssues = true
reportPropertyTypeMismatch = true
reportWildcardImportFromLibrary = true
reportUntypedClassDecorator = false
reportUntypedNamedTuple = true
reportPrivateUsage = true
reportPrivateImportUsage = true
reportInconsistentConstructor = true
reportMissingSuperCall = false
reportUninitializedInstanceVariable = true
reportInvalidStringEscapeSequence = true
reportMissingParameterType = true
reportImplicitStringConcatenation = false
reportUndefinedVariable = true
reportUnboundVariable = true
reportInvalidStubStatement = true
reportIncompleteStub = true
reportUnsupportedDunderAll = true
reportUnusedCoroutine = true
reportUnnecessaryTypeIgnoreComment = true
reportMatchNotExhaustive = true
10 changes: 0 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,3 @@ previous = true
domain = ckanext-or_facet
directory = ckanext/or_facet/i18n
statistics = true

[tool:pytest]
filterwarnings =
ignore::sqlalchemy.exc.SADeprecationWarning
ignore::sqlalchemy.exc.SAWarning
ignore::DeprecationWarning
addopts = --pdbcls=IPython.terminal.debugger:TerminalPdb

[yapf]
column_limit = 79

0 comments on commit 3b40f5a

Please sign in to comment.