Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add another testcase for squashing #13830

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions weblate/addons/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@

class TestAddonMixin:
def setUp(self) -> None:
super().setUp()

Check failure on line 101 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

"setUp" undefined in superclass
ADDONS.data[NoOpAddon.name] = NoOpAddon
ADDONS.data[ExampleAddon.name] = ExampleAddon
ADDONS.data[CrashAddon.name] = CrashAddon
ADDONS.data[ExamplePreAddon.name] = ExamplePreAddon

def tearDown(self) -> None:
super().tearDown()

Check failure on line 108 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

"tearDown" undefined in superclass
del ADDONS.data[NoOpAddon.name]
del ADDONS.data[ExampleAddon.name]
del ADDONS.data[CrashAddon.name]
Expand All @@ -119,7 +119,7 @@
def test_example(self) -> None:
self.assertTrue(ExampleAddon.can_install(self.component, None))
addon = ExampleAddon.create(component=self.component)
addon.pre_commit(None, "", True)

Check failure on line 122 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "pre_commit" of "BaseAddon" has incompatible type "None"; expected "Translation"

def test_create(self) -> None:
addon = NoOpAddon.create(component=self.component)
Expand All @@ -142,8 +142,8 @@

def test_add_form(self) -> None:
form = NoOpAddon.get_add_form(None, component=self.component, data={})
self.assertTrue(form.is_valid())

Check failure on line 145 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "BaseAddonForm | None" has no attribute "is_valid"
form.save()

Check failure on line 146 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "BaseAddonForm | None" has no attribute "save"
self.assertEqual(self.component.addon_set.count(), 1)

addon = self.component.addon_set.all()[0]
Expand All @@ -151,8 +151,8 @@

def test_add_form_project_addon(self) -> None:
form = NoOpAddon.get_add_form(None, project=self.component.project, data={})
self.assertTrue(form.is_valid())

Check failure on line 154 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "BaseAddonForm | None" has no attribute "is_valid"
form.save()

Check failure on line 155 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "BaseAddonForm | None" has no attribute "save"
self.assertEqual(self.component.project.addon_set.count(), 1)

addon = self.component.project.addon_set.all()[0]
Expand All @@ -160,8 +160,8 @@

def test_add_form_site_wide_addon(self) -> None:
form = NoOpAddon.get_add_form(None, data={})
self.assertTrue(form.is_valid())

Check failure on line 163 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "BaseAddonForm | None" has no attribute "is_valid"
form.save()

Check failure on line 164 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Item "None" of "BaseAddonForm | None" has no attribute "save"
addon_object = Addon.objects.filter(name="weblate.base.test")
self.assertEqual(addon_object.count(), 1)

Expand Down Expand Up @@ -363,7 +363,7 @@
self.assertTrue(GettextAuthorComments.can_install(translation.component, None))
addon = GettextAuthorComments.create(component=translation.component)
addon.pre_commit(translation, "Stojan Jakotyc <[email protected]>", True)
with open(translation.get_filename()) as handle:

Check failure on line 366 in weblate/addons/tests.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "open" has incompatible type "str | None"; expected "int | str | bytes | PathLike[str] | PathLike[bytes]"
content = handle.read()
self.assertIn("Stojan Jakotyc", content)

Expand Down Expand Up @@ -1221,9 +1221,9 @@
component=component, configuration={"squash": mode}
)

def edit(self) -> None:
def edit(self, *, repeated: bool = False) -> None:
for lang in ("cs", "de"):
self.change_unit("Nazdar svete!\n", "Hello, world!\n", lang)
self.change_unit("Nazdar svete!\n", "Hello, world!\n", language=lang)
self.component.commit_pending("test", None)
self.change_unit(
"Diky za pouziti Weblate.",
Expand All @@ -1233,16 +1233,30 @@
)
self.component.commit_pending("test", None)

# Add commit on the same unit, that is touched by anotheruser
if repeated:
self.change_unit(
"Danke für die Benutzung von Weblate.",
"Thank you for using Weblate.",
language="de",
)
self.component.commit_pending("test", None)

def test_squash(
self, mode: str = "all", expected: int = 1, sitewide: bool = False
self,
mode: str = "all",
expected: int = 1,
*,
sitewide: bool = False,
repeated: bool = False,
) -> None:
addon = self.create(mode=mode, sitewide=sitewide)
repo = self.component.repository
self.assertEqual(repo.count_outgoing(), 0)
# Test no-op behavior
addon.post_commit(self.component, True)
# Make some changes
self.edit()
self.edit(repeated=repeated)
self.assertEqual(repo.count_outgoing(), expected)

def test_squash_sitewide(self) -> None:
Expand All @@ -1265,6 +1279,9 @@
self.component.commit_pending("test", None)
self.assertEqual(self.component.repository.count_outgoing(), 3)

def test_multiple_authors_on_same_file(self) -> None:
self.test_squash("author", 3, repeated=True)

def test_commit_message(self) -> None:
commit_message = "Squashed commit message"
GitSquashAddon.create(
Expand Down
Loading