sapling/eden/integration/hg/journal_test.py
John Reese 2940ae3a2a apply import merging for fbcode (4 of 11)
Summary:
Applies new import merging and sorting from µsort v1.0.

When merging imports, µsort will make a best-effort to move associated
comments to match merged elements, but there are known limitations due to
the diynamic nature of Python and developer tooling. These changes should
not produce any dangerous runtime changes, but may require touch-ups to
satisfy linters and other tooling.

Note that µsort uses case-insensitive, lexicographical sorting, which
results in a different ordering compared to isort. This provides a more
consistent sorting order, matching the case-insensitive order used when
sorting import statements by module name, and ensures that "frog", "FROG",
and "Frog" always sort next to each other.

For details on µsort's sorting and merging semantics, see the user guide:
https://usort.readthedocs.io/en/stable/guide.html#sorting

Reviewed By: lisroach

Differential Revision: D36402162

fbshipit-source-id: 6d180e9003d466c4f866fc9d454c6531766ca1dd
2022-05-15 12:53:03 -07:00

54 lines
1.8 KiB
Python

#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
from eden.integration.lib import hgrepo
from .lib.hg_extension_test_base import EdenHgTestCase, hg_test, JournalEntry
@hg_test
# pyre-ignore[13]: T62487924
class JournalTest(EdenHgTestCase):
commit1: str
def populate_backing_repo(self, repo: hgrepo.HgRepository) -> None:
repo.write_file("hello.txt", "hola")
repo.write_file("foo/bar.txt", "test\n")
repo.write_file("foo/subdir/test.txt", "test\n")
self.commit1 = repo.commit("Initial commit.")
def test_journal(self) -> None:
self.assert_journal_empty()
# Create a new commit
self.assert_status_empty()
self.write_file("foo/bar.txt", "test version 2\n")
self.assert_status({"foo/bar.txt": "M"})
commit2 = self.repo.commit("Updated bar.txt\n")
# Check that the journal was updated
self.assert_journal(
JournalEntry(name=".", old=self.commit1, new=commit2, command="^commit")
)
# Amend the commit
self.write_file("foo/bar.txt", "v3\nother stuff\n")
commit3 = self.repo.commit("Updated bar.txt\n", amend=True)
# Check out commit1, then commit3 again
self.repo.update(self.commit1)
self.repo.update(commit3)
# Check the journal
self.assert_journal(
JournalEntry(name=".", old=self.commit1, new=commit2, command="^commit"),
JournalEntry(
name=".", old=commit2, new=commit3, command="^commit.* --amend"
),
JournalEntry(name=".", old=commit3, new=self.commit1, command="^update"),
JournalEntry(name=".", old=self.commit1, new=commit3, command="^update"),
)