From 73262ab5a5dda69a531ad4e5d3ecc71abd3ed3cf Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Tue, 15 Oct 2024 23:54:18 +0900 Subject: [PATCH] test: add BrewfileTestLinux for Linux-specific tests test: update Brewfile input handling based on OS test: conditionally assert Linux and macOS specific brew inputs test: ensure correct output for Linux files during write --- tests/files/BrewfileTestLinux | 23 ++++++++++++++++++ tests/test_brew_info.py | 46 ++++++++++++++--------------------- 2 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 tests/files/BrewfileTestLinux diff --git a/tests/files/BrewfileTestLinux b/tests/files/BrewfileTestLinux new file mode 100644 index 00000000..f4a6bc57 --- /dev/null +++ b/tests/files/BrewfileTestLinux @@ -0,0 +1,23 @@ +# Before commands +before echo before + +# tap repositories and their packages + +tap homebrew/core +brew python@3.10 +brew vim --HEAD + +# Main file +main BrewfileMain + +# Additional files +file BrewfileExt +file BrewfileExt2 +file BrewfileNotExist +file ~/BrewfileHomeForTestingNotExists + +# Other commands +echo other commands + +# After commands +after echo after diff --git a/tests/test_brew_info.py b/tests/test_brew_info.py index f6295be2..3d28a240 100644 --- a/tests/test_brew_info.py +++ b/tests/test_brew_info.py @@ -7,8 +7,9 @@ @pytest.fixture def brew_info(): + file = "BrewfileTest" if brew_file.is_mac() else "BrewfileTestLinux" bf = brew_file.BrewFile( - {"input": Path(__file__).parent / "files" / "BrewfileTest"} + {"input": Path(__file__).parent / "files" / file} ) return bf.brewinfo @@ -254,13 +255,18 @@ def test_read(brew_info): brew_info.read() assert brew_info.brew_input_opt == {"python@3.10": "", "vim": " --HEAD"} assert brew_info.brew_input == ["python@3.10", "vim"] - assert brew_info.tap_input == [ - "homebrew/core", - "homebrew/cask", - "rcmdnk/rcmdnkcask", - ] - assert brew_info.cask_input == ["iterm2", "font-migu1m"] - assert brew_info.appstore_input == ["Keynote"] + if brew_file.is_mac(): + assert brew_info.tap_input == [ + "homebrew/core", + "homebrew/cask", + "rcmdnk/rcmdnkcask", + ] + assert brew_info.cask_input == ["iterm2", "font-migu1m"] + assert brew_info.appstore_input == ["Keynote"] + else: + assert brew_info.tap_input == [ + "homebrew/core", + ] assert brew_info.main_input == ["BrewfileMain"] assert brew_info.file_input == [ "BrewfileMain", @@ -318,26 +324,18 @@ def test_write(brew_info, tmp_path, tap): brew_info.write() with open(default_file) as f1: default_txt = f1.readlines() - if not brew_file.is_mac(): - default_txt = [ - x - for x in default_txt - if not x.startswith("cask ") and not x.startswith("appstore ") - ] default_txt = "".join(default_txt) - if not brew_file.is_mac(): - default_txt = default_txt.replace( - "# App Store applications\n\n", "" - ) with open(tmp_file) as f2: tmp_txt = f2.read() assert tmp_txt == default_txt brew_info.helper.opt["form"] = "bundle" brew_info.write() if brew_file.is_mac(): + cask_tap = "tap 'homebrew/cask'\n\ntap 'rcmdnk/rcmdnkcask'\n" appstore1 = "\n# App Store applications\nmas '', id: Keynote\n" appstore2 = "\n# App Store applications\nmas install Keynote\n" else: + cask_tap = "" appstore1 = "" appstore2 = "" @@ -350,11 +348,7 @@ def test_write(brew_info, tmp_path, tap): # tap repositories and their packages tap 'homebrew/core' - -tap 'homebrew/cask' - -tap 'rcmdnk/rcmdnkcask' -{appstore1} +{cask_tap}{appstore1} # Main file #main 'BrewfileMain' @@ -396,11 +390,7 @@ def test_write(brew_info, tmp_path, tap): # tap repositories and their packages brew tap homebrew/core - -brew tap homebrew/cask - -brew tap rcmdnk/rcmdnkcask -{appstore2} +{cask_tap}{appstore2} # Main file #main BrewfileMain