From b139cdb970217acb5a80357483c46753ffd63dfa Mon Sep 17 00:00:00 2001 From: Max Mynter Date: Wed, 21 Feb 2024 14:28:01 +0100 Subject: [PATCH] Add tests for uncommitted changes in transaction warning --- tests/test_transactions.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_transactions.py b/tests/test_transactions.py index 3952d754..032c61a2 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -146,3 +146,33 @@ def test_transaction_bad_repo(fs: LakeFSFileSystem) -> None: with pytest.raises(ValueError, match="repository .* does not exist"): with fs.transaction(repository="REEEE"): pass + + +def test_warn_uncommitted_changes( + random_file_factory: RandomFileFactory, + fs: LakeFSFileSystem, + repository: Repository, + temp_branch: Branch, +) -> None: + random_file = random_file_factory.make() + + lpath = str(random_file) + + with pytest.warns(match="uncommitted changes.*lost"): + with fs.transaction(repository, temp_branch) as tx: + fs.put_file(lpath, f"{repository.id}/{tx.branch.id}/{random_file.name}") + + +def test_warn_uncommitted_changes_on_persisted_branch( + random_file_factory: RandomFileFactory, + fs: LakeFSFileSystem, + repository: Repository, + temp_branch: Branch, +) -> None: + random_file = random_file_factory.make() + + lpath = str(random_file) + + with pytest.warns(match="uncommitted changes(?:(?!lost).)*$"): + with fs.transaction(repository, temp_branch, delete="never") as tx: + fs.put_file(lpath, f"{repository.id}/{tx.branch.id}/{random_file.name}")