summaryrefslogtreecommitdiffstats
path: root/tests/test_style.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_style.py84
1 files changed, 45 insertions, 39 deletions
diff --git a/tests/test_style.py b/tests/test_style.py
index d3cfb14..8f5b6ca 100644
--- a/tests/test_style.py
+++ b/tests/test_style.py
@@ -7,7 +7,7 @@ from debputy.yaml.compat import CommentedMap
from debputy.lsp.maint_prefs import (
MaintainerPreferenceTable,
determine_effective_preference,
- EffectivePreference,
+ EffectiveFormattingPreference,
_WAS_DEFAULTS,
)
from debputy.packages import SourcePackage
@@ -16,19 +16,25 @@ from debputy.packages import SourcePackage
def test_load_styles() -> None:
styles = MaintainerPreferenceTable.load_preferences()
assert "niels@thykier.net" in styles.maintainer_preferences
- nt_style = styles.maintainer_preferences["niels@thykier.net"]
+ nt_maint_pref = styles.maintainer_preferences["niels@thykier.net"]
# Note this is data dependent; if it fails because the style changes, update the test
- assert nt_style.canonical_name == "Niels Thykier"
- assert not nt_style.is_packaging_team
- assert nt_style.formatting_deb822_normalize_field_content
- assert nt_style.formatting_deb822_short_indent
- assert nt_style.formatting_deb822_always_wrap
- assert nt_style.formatting_deb822_trailing_separator
- assert nt_style.formatting_deb822_max_line_length == 79
- assert not nt_style.formatting_deb822_normalize_stanza_order
+ assert nt_maint_pref.canonical_name == "Niels Thykier"
+ assert not nt_maint_pref.is_packaging_team
+ black_style = styles.named_styles["black"]
+ nt_style = nt_maint_pref.formatting
+ assert nt_style is not None
+ assert black_style == black_style
- # TODO: Not implemented yet
- assert not nt_style.formatting_deb822_normalize_field_order
+
+def test_load_no_styles() -> None:
+ styles = MaintainerPreferenceTable.load_preferences()
+ assert "packages@qa.debian.org" in styles.maintainer_preferences
+ qa_maint_pref = styles.maintainer_preferences["packages@qa.debian.org"]
+ assert qa_maint_pref.canonical_name == "Debian QA Group"
+ assert qa_maint_pref.is_packaging_team
+ # Orphaned packages do not have a predefined style, since Debian (nor Debian QA) have
+ # one well-defined style.
+ assert qa_maint_pref.formatting is None
def test_load_named_styles() -> None:
@@ -36,15 +42,15 @@ def test_load_named_styles() -> None:
assert "black" in styles.named_styles
black_style = styles.named_styles["black"]
# Note this is data dependent; if it fails because the style changes, update the test
- assert black_style.formatting_deb822_normalize_field_content
- assert black_style.formatting_deb822_short_indent
- assert black_style.formatting_deb822_always_wrap
- assert black_style.formatting_deb822_trailing_separator
- assert black_style.formatting_deb822_max_line_length == 79
- assert not black_style.formatting_deb822_normalize_stanza_order
+ assert black_style.deb822_normalize_field_content
+ assert black_style.deb822_short_indent
+ assert black_style.deb822_always_wrap
+ assert black_style.deb822_trailing_separator
+ assert black_style.deb822_max_line_length == 79
+ assert not black_style.deb822_normalize_stanza_order
# TODO: Not implemented yet
- assert not black_style.formatting_deb822_normalize_field_order
+ assert not black_style.deb822_normalize_field_order
def test_compat_styles() -> None:
@@ -56,11 +62,11 @@ def test_compat_styles() -> None:
assert "random-package@packages.debian.org" not in styles.maintainer_preferences
assert "random@example.org" not in styles.maintainer_preferences
- nt_pref = styles.maintainer_preferences["niels@thykier.net"].as_effective_pref()
- zeha_pref = styles.maintainer_preferences["zeha@debian.org"].as_effective_pref()
+ nt_style = styles.maintainer_preferences["niels@thykier.net"].formatting
+ zeha_style = styles.maintainer_preferences["zeha@debian.org"].formatting
# Data dependency
- assert nt_pref == zeha_pref
+ assert nt_style == zeha_style
fields = Deb822(
{
@@ -72,7 +78,7 @@ def test_compat_styles() -> None:
src = SourcePackage(fields)
effective_style, tool, _ = determine_effective_preference(styles, src, None)
- assert effective_style == nt_pref
+ assert effective_style == nt_style
assert tool == "debputy reformat"
fields["Uploaders"] = (
@@ -81,8 +87,8 @@ def test_compat_styles() -> None:
src = SourcePackage(fields)
effective_style, tool, _ = determine_effective_preference(styles, src, None)
- assert effective_style == nt_pref
- assert effective_style == zeha_pref
+ assert effective_style == nt_style
+ assert effective_style == zeha_style
assert tool == "debputy reformat"
fields["Uploaders"] = (
@@ -112,7 +118,7 @@ def test_compat_styles_team_maint() -> None:
team_style = styles.maintainer_preferences["team@lists.debian.org"]
assert team_style.is_packaging_team
effective_style, tool, _ = determine_effective_preference(styles, src, None)
- assert effective_style == team_style.as_effective_pref()
+ assert effective_style == team_style.formatting
assert tool is None
@@ -158,7 +164,7 @@ def test_was_from_salsa_ci_style() -> None:
{"variables": CommentedMap({"SALSA_CI_DISABLE_WRAP_AND_SORT": "no"})}
)
effective_style, tool, _ = determine_effective_preference(styles, src, salsa_ci)
- was_style = EffectivePreference(**_WAS_DEFAULTS)
+ was_style = EffectiveFormattingPreference(**_WAS_DEFAULTS)
assert effective_style == was_style
assert tool == "wrap-and-sort"
@@ -169,37 +175,37 @@ def test_was_from_salsa_ci_style() -> None:
(
"-a",
{
- "formatting_deb822_always_wrap": True,
+ "deb822_always_wrap": True,
},
),
(
"-sa",
{
- "formatting_deb822_always_wrap": True,
- "formatting_deb822_short_indent": True,
+ "deb822_always_wrap": True,
+ "deb822_short_indent": True,
},
),
(
"-sa --keep-first",
{
- "formatting_deb822_always_wrap": True,
- "formatting_deb822_short_indent": True,
+ "deb822_always_wrap": True,
+ "deb822_short_indent": True,
},
),
(
"-sab --keep-first",
{
- "formatting_deb822_always_wrap": True,
- "formatting_deb822_short_indent": True,
- "formatting_deb822_normalize_stanza_order": True,
+ "deb822_always_wrap": True,
+ "deb822_short_indent": True,
+ "deb822_normalize_stanza_order": True,
},
),
(
"-sab --no-keep-first",
{
- "formatting_deb822_always_wrap": True,
- "formatting_deb822_short_indent": True,
- "formatting_deb822_normalize_stanza_order": False,
+ "deb822_always_wrap": True,
+ "deb822_short_indent": True,
+ "deb822_normalize_stanza_order": False,
},
),
],
@@ -232,7 +238,7 @@ def test_was_from_salsa_ci_style_args(
assert effective_style is None
assert tool is None
else:
- was_style = EffectivePreference(**_WAS_DEFAULTS).replace(
+ was_style = EffectiveFormattingPreference(**_WAS_DEFAULTS).replace(
**style_delta,
)