summaryrefslogtreecommitdiffstats
path: root/tests/test_style.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_style.py')
-rw-r--r--tests/test_style.py122
1 files changed, 115 insertions, 7 deletions
diff --git a/tests/test_style.py b/tests/test_style.py
index 9ce83bd..cae4510 100644
--- a/tests/test_style.py
+++ b/tests/test_style.py
@@ -1,7 +1,15 @@
+from typing import Mapping, Any, Optional
+
import pytest
from debian.deb822 import Deb822
-
-from debputy.lsp.style_prefs import StylePreferenceTable, determine_effective_style
+from debputy.yaml.compat import CommentedMap
+
+from debputy.lsp.style_prefs import (
+ StylePreferenceTable,
+ determine_effective_style,
+ EffectivePreference,
+ _WAS_DEFAULTS,
+)
from debputy.packages import SourcePackage
@@ -63,7 +71,7 @@ def test_compat_styles() -> None:
)
src = SourcePackage(fields)
- effective_style = determine_effective_style(styles, src)
+ effective_style = determine_effective_style(styles, src, None)
assert effective_style == nt_pref
fields["Uploaders"] = (
@@ -71,7 +79,7 @@ def test_compat_styles() -> None:
)
src = SourcePackage(fields)
- effective_style = determine_effective_style(styles, src)
+ effective_style = determine_effective_style(styles, src, None)
assert effective_style == nt_pref
assert effective_style == zeha_pref
@@ -80,7 +88,7 @@ def test_compat_styles() -> None:
)
src = SourcePackage(fields)
- effective_style = determine_effective_style(styles, src)
+ effective_style = determine_effective_style(styles, src, None)
assert effective_style is None
@@ -100,7 +108,7 @@ def test_compat_styles_team_maint() -> None:
assert "random@example.org" not in styles.maintainer_preferences
team_style = styles.maintainer_preferences["team@lists.debian.org"]
assert team_style.is_packaging_team
- effective_style = determine_effective_style(styles, src)
+ effective_style = determine_effective_style(styles, src, None)
assert effective_style == team_style.as_effective_pref()
@@ -117,5 +125,105 @@ def test_x_style() -> None:
assert "random@example.org" not in styles.maintainer_preferences
assert "black" in styles.named_styles
black_style = styles.named_styles["black"]
- effective_style = determine_effective_style(styles, src)
+ effective_style = determine_effective_style(styles, src, None)
assert effective_style == black_style
+
+
+def test_was_from_salsa_ci_style() -> None:
+ styles = StylePreferenceTable.load_styles()
+ fields = Deb822(
+ {
+ "Package": "foo",
+ "Maintainer": "Random Developer <random@example.org>",
+ },
+ )
+ src = SourcePackage(fields)
+ assert "random@example.org" not in styles.maintainer_preferences
+ effective_style = determine_effective_style(styles, src, None)
+ assert effective_style is None
+ salsa_ci = CommentedMap(
+ {"variables": CommentedMap({"SALSA_CI_DISABLE_WRAP_AND_SORT": "yes"})}
+ )
+ effective_style = determine_effective_style(styles, src, salsa_ci)
+ assert effective_style is None
+
+ salsa_ci = CommentedMap(
+ {"variables": CommentedMap({"SALSA_CI_DISABLE_WRAP_AND_SORT": "no"})}
+ )
+ effective_style = determine_effective_style(styles, src, salsa_ci)
+ was_style = EffectivePreference(**_WAS_DEFAULTS)
+ assert effective_style == was_style
+
+
+@pytest.mark.parametrize(
+ "was_args,style_delta",
+ [
+ (
+ "-a",
+ {
+ "formatting_deb822_always_wrap": True,
+ },
+ ),
+ (
+ "-sa",
+ {
+ "formatting_deb822_always_wrap": True,
+ "formatting_deb822_short_indent": True,
+ },
+ ),
+ (
+ "-sa --keep-first",
+ {
+ "formatting_deb822_always_wrap": True,
+ "formatting_deb822_short_indent": True,
+ },
+ ),
+ (
+ "-sab --keep-first",
+ {
+ "formatting_deb822_always_wrap": True,
+ "formatting_deb822_short_indent": True,
+ "formatting_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,
+ },
+ ),
+ ],
+)
+def test_was_from_salsa_ci_style_args(
+ was_args: str, style_delta: Optional[Mapping[str, Any]]
+) -> None:
+ styles = StylePreferenceTable.load_styles()
+ fields = Deb822(
+ {
+ "Package": "foo",
+ "Maintainer": "Random Developer <random@example.org>",
+ },
+ )
+ src = SourcePackage(fields)
+ assert "random@example.org" not in styles.maintainer_preferences
+ salsa_ci = CommentedMap(
+ {
+ "variables": CommentedMap(
+ {
+ "SALSA_CI_DISABLE_WRAP_AND_SORT": "no",
+ "SALSA_CI_WRAP_AND_SORT_ARGS": was_args,
+ }
+ )
+ }
+ )
+ effective_style = determine_effective_style(styles, src, salsa_ci)
+ if style_delta is None:
+ assert effective_style is None
+ else:
+ was_style = EffectivePreference(**_WAS_DEFAULTS).replace(
+ **style_delta,
+ )
+
+ assert effective_style == was_style