Files
pkgmgr/tests/unit/pkgmgr/actions/install/installers/nix/test_textparse.py
Kevin Veen-Birkenbach 328203ccd7
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / linter-shell (push) Has been cancelled
Mark stable commit / linter-python (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
**test(nix): add comprehensive unittest coverage for nix installer helpers**
* Add reusable fakes for runner and retry logic
* Cover conflict resolution paths (store-prefix, output-token, textual fallback)
* Add unit tests for profile parsing, normalization, matching, and text parsing
* Verify installer core behavior for success, mandatory failure, and optional failure
* Keep tests Nix-free using pure unittest + mocks

https://chatgpt.com/share/693efe80-d928-800f-98b7-0aaafee1d32a
2025-12-14 19:27:26 +01:00

31 lines
1.2 KiB
Python

from __future__ import annotations
import unittest
from pkgmgr.actions.install.installers.nix.textparse import NixConflictTextParser
class TestNixConflictTextParser(unittest.TestCase):
def test_remove_tokens_parses_unquoted_and_quoted(self) -> None:
t = NixConflictTextParser()
text = '''
nix profile remove pkgmgr
nix profile remove 'pkgmgr-1'
nix profile remove "default-2"
'''
tokens = t.remove_tokens(text)
self.assertEqual(tokens, ["pkgmgr", "pkgmgr-1", "default-2"])
def test_existing_store_prefixes_extracts_existing_section_only(self) -> None:
t = NixConflictTextParser()
text = '''
error: An existing package already provides the following file:
/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-pkgmgr/bin/pkgmgr
/nix/store/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-pkgmgr/share/doc
This is the conflicting file from the new package:
/nix/store/cccccccccccccccccccccccccccccccc-pkgmgr/bin/pkgmgr
'''
prefixes = t.existing_store_prefixes(text)
self.assertEqual(len(prefixes), 2)
self.assertTrue(prefixes[0].startswith("/nix/store/"))