11"""Example folder tests"""
22
3+ import shutil
34from os import walk
45from pathlib import Path
56from typing import cast
67
78import pytest
9+ from typer .testing import CliRunner
10+
11+ from cppython .console .entry import app
12+
13+ runner = CliRunner ()
814
915
1016class TestExamples :
@@ -18,7 +24,8 @@ def _examples() -> list[Path]:
1824 for dirpath , _ , filenames in walk ('examples' ):
1925 for filename in filenames :
2026 if filename == 'pyproject.toml' :
21- matching_directories .append (Path (dirpath ))
27+ absolute_path = Path (dirpath ).absolute ()
28+ matching_directories .append (absolute_path )
2229 break
2330
2431 return matching_directories
@@ -40,7 +47,43 @@ def fixture_example_directory(
4047 return directory
4148
4249 @staticmethod
43- def test_example (example_directory : Path ) -> None :
44- """Tests the examples """
50+ def test_example_directory (example_directory : Path ) -> None :
51+ """Verify that the fixture is returning the right data """
4552 assert example_directory .is_dir ()
4653 assert (example_directory / 'pyproject.toml' ).is_file ()
54+
55+ @staticmethod
56+ def test_info (example_directory : Path ) -> None :
57+ """Verifies that the info command functions with CPPython hooks"""
58+ with runner .isolated_filesystem () as temp_directory :
59+ shutil .copytree (example_directory , temp_directory , dirs_exist_ok = True )
60+
61+ result = runner .invoke (app , ['info' ])
62+ assert result .exit_code == 0
63+
64+ @staticmethod
65+ def test_list (example_directory : Path ) -> None :
66+ """Verifies that the list command functions with CPPython hooks"""
67+ with runner .isolated_filesystem () as temp_directory :
68+ shutil .copytree (example_directory , temp_directory , dirs_exist_ok = True )
69+
70+ result = runner .invoke (app , ['list' ])
71+ assert result .exit_code == 0
72+
73+ @staticmethod
74+ def test_update (example_directory : Path ) -> None :
75+ """Verifies that the update command functions with CPPython hooks"""
76+ with runner .isolated_filesystem () as temp_directory :
77+ shutil .copytree (example_directory , temp_directory , dirs_exist_ok = True )
78+
79+ result = runner .invoke (app , ['update' ])
80+ assert result .exit_code == 0
81+
82+ @staticmethod
83+ def test_install (example_directory : Path ) -> None :
84+ """Verifies that the install command functions with CPPython hooks"""
85+ with runner .isolated_filesystem () as temp_directory :
86+ shutil .copytree (example_directory , temp_directory , dirs_exist_ok = True )
87+
88+ result = runner .invoke (app , ['install' ])
89+ assert result .exit_code == 0
0 commit comments