Skip to content

Commit

Permalink
add multiple install test for completion coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Jan 8, 2025
1 parent 17abfeb commit ca2d25d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-linux-py${{ matrix.python-version }}-dj${{ matrix.django-version }}
path: py${{ matrix.python-version }}-dj${{ matrix.django-version }}.coverage
path: py${{ matrix.python-version }}-linux-dj${{ matrix.django-version }}.coverage

test-windows:
runs-on: windows-latest
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-windows-py${{ matrix.python-version }}-dj${{ matrix.django-version }}
path: py${{ matrix.python-version }}-dj${{ matrix.django-version }}.coverage
path: py${{ matrix.python-version }}-windows-dj${{ matrix.django-version }}.coverage

test-macos:
runs-on: macos-latest
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-macos-py${{ matrix.python-version }}-dj${{ matrix.django-version }}
path: py${{ matrix.python-version }}-dj${{ matrix.django-version }}.coverage
path: py${{ matrix.python-version }}-macos-dj${{ matrix.django-version }}.coverage

linux-bash-complete:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -229,8 +229,8 @@ jobs:
- name: Store coverage files
uses: actions/upload-artifact@v4
with:
name: coverage-linux-complete-py${{ matrix.python-version }}-dj${{ matrix.django-version }}
path: linux-complete-py${{ matrix.python-version }}-dj${{ matrix.django-version }}.coverage
name: coverage-linux-bash-py${{ matrix.python-version }}-dj${{ matrix.django-version }}
path: linux-bash-py${{ matrix.python-version }}-dj${{ matrix.django-version }}.coverage

macos-zsh-complete:
runs-on: macos-latest
Expand Down
46 changes: 44 additions & 2 deletions tests/shellcompletion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,25 @@ class _InstalledScriptCompleteTestCase(_CompleteTestCase):

@classmethod
def setUpClass(cls):
cls.install_script()
super().setUpClass()

@classmethod
def tearDownClass(cls):
cls.remove_script()
super().tearDownClass()

@classmethod
def install_script(cls, script=None):
if not script:
script = cls.manage_script
lines = []
with open(cls.MANAGE_SCRIPT_TMPL, "r") as f:
for line in f.readlines():
if line.startswith("#!{{shebang}}"):
line = f"#!{sys.executable}\n"
lines.append(line)
exe = Path(sys.executable).parent / cls.manage_script
exe = Path(sys.executable).parent / script
with open(exe, "w") as f:
for line in lines:
f.write(line)
Expand All @@ -412,4 +424,34 @@ def setUpClass(cls):
with open(exe.with_suffix(".cmd"), "w") as f:
f.write(f'@echo off{os.linesep}"{sys.executable}" "%~dp0{exe.name}" %*')
os.chmod(exe, os.stat(exe.with_suffix(".cmd")).st_mode | 0o111)
super().setUpClass()

@classmethod
def remove_script(cls, script=None):
if not script:
script = cls.manage_script
exe = Path(sys.executable).parent / script
exe.unlink(missing_ok=True)
exe.with_suffix(".cmd").unlink(missing_ok=True)

def test_multi_install(self):
parts = self.manage_script.split(".")
manage2 = ".".join(parts[0] + "2", *parts[1:])
try:
self.install_script(script=manage2)
self.install()
self.verify_install()
self.install(script=manage2)
self.verify_install(script=manage2)

completions = self.get_completions(self.manage_script, "complet")
self.assertIn("completion", completions)

completions = self.get_completions(manage2, "complet")
self.assertIn("completion", completions)

self.remove()
self.verify_remove()
self.remove(script=manage2)
self.verify_remove(script=manage2)
finally:
self.remove_script(script=manage2)

0 comments on commit ca2d25d

Please sign in to comment.