Skip to content

Commit

Permalink
test: add BrewfileTestLinux for Linux-specific tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rcmdnk committed Oct 15, 2024
1 parent 9c47ab9 commit 73262ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
23 changes: 23 additions & 0 deletions tests/files/BrewfileTestLinux
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Before commands
before echo before

# tap repositories and their packages

tap homebrew/core
brew [email protected]
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
46 changes: 18 additions & 28 deletions tests/test_brew_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -254,13 +255,18 @@ def test_read(brew_info):
brew_info.read()
assert brew_info.brew_input_opt == {"[email protected]": "", "vim": " --HEAD"}
assert brew_info.brew_input == ["[email protected]", "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",
Expand Down Expand Up @@ -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 = ""

Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73262ab

Please sign in to comment.