Skip to content

Commit 79170b1

Browse files
authored
Merge pull request #71 from cadenmyers13/printing-info
`print_info` test and function
2 parents 9ce66e6 + d7b0a8e commit 79170b1

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

news/printing-info.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Added ``print_info`` function.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/cmi/packsmanager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,25 @@ def install_pack(self, identifier: str | Path) -> None:
347347
plog.info("Pack '%s' installation complete.", path.stem)
348348
else:
349349
plog.error("Pack '%s' installation failed.", path.stem)
350+
351+
def print_info(self) -> None:
352+
"""Print information about available packs and examples."""
353+
uninstalled_packs = []
354+
installed_packs = []
355+
for pack in self.available_packs():
356+
if self.check_pack(pack):
357+
installed_packs.append(pack)
358+
else:
359+
uninstalled_packs.append(pack)
360+
print("Installed Packs:")
361+
for pack in installed_packs:
362+
print(f" {pack}")
363+
print("\nAvailable Packs to Install:")
364+
for pack in uninstalled_packs:
365+
print(f" {pack}")
366+
print("\nExamples:")
367+
examples_dict = self.available_examples()
368+
for pack, examples in examples_dict.items():
369+
print(f" {pack}:")
370+
for ex_name, _ in examples:
371+
print(f" - {ex_name}")

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ def example_cases(tmp_path_factory):
9696
case5req_dir = root_temp_dir / "case5" / "requirements" / "packs"
9797
case5req_dir.mkdir(parents=True, exist_ok=True)
9898

99+
fake_env = root_temp_dir / "case5" / "fake_env"
100+
fake_env.mkdir(parents=True, exist_ok=True)
101+
(case5req_dir / "packA.txt").write_text("requests")
102+
(case5req_dir / "packB.txt").write_text("attrs")
103+
99104
yield root_temp_dir
100105

101106

tests/test_packsmanager.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import subprocess
34
from pathlib import Path
45

56
import pytest
@@ -342,3 +343,59 @@ def test_copy_examples_force(example_cases, expected_paths, force):
342343
original_path = examples_dir / path
343344
if copied_path.is_file() and original_path.is_file():
344345
assert copied_path.read_text() == original_path.read_text()
346+
347+
348+
install_params = [
349+
( # input: install requirements for packA
350+
# expected: print_info output showing packA installed but not packB
351+
("packA",),
352+
"""Installed Packs:
353+
packA
354+
355+
Available Packs to Install:
356+
packB
357+
358+
Examples:
359+
packA:
360+
- ex1
361+
- ex2
362+
packB:
363+
- ex1
364+
- ex3
365+
- ex4""",
366+
),
367+
]
368+
369+
370+
@pytest.mark.parametrize("packs_to_install,expected", install_params)
371+
def test_print_info(packs_to_install, expected, example_cases, capsys):
372+
case5dir = example_cases / "case5"
373+
env_dir = case5dir / "fake_env"
374+
req_dir = case5dir / "requirements" / "packs"
375+
subprocess.run(
376+
["conda", "create", "-y", "-p", str(env_dir)],
377+
check=True,
378+
capture_output=True,
379+
text=True,
380+
)
381+
for pack in packs_to_install:
382+
req_file = req_dir / f"{pack}.txt"
383+
subprocess.run(
384+
[
385+
"conda",
386+
"install",
387+
"-y",
388+
"--file",
389+
str(req_file),
390+
"-p",
391+
str(env_dir),
392+
],
393+
check=True,
394+
capture_output=True,
395+
text=True,
396+
)
397+
pm = PacksManager(root_path=case5dir)
398+
pm.print_info()
399+
captured = capsys.readouterr()
400+
actual = captured.out
401+
assert actual.strip() == expected.strip()

0 commit comments

Comments
 (0)