1+ """
2+ Fast CI tests that don't make real API calls.
3+ These tests validate the CLI interface and basic functionality without downloading papers.
4+ """
5+
6+ import os
7+ import sys
8+ import subprocess
9+ from pathlib import Path
10+
11+
12+ def test_cli_help ():
13+ """Test that the CLI help command works"""
14+ result = subprocess .run ([sys .executable , "-m" , "pygetpapers.pygetpapers" , "--help" ],
15+ capture_output = True , text = True , timeout = 30 )
16+ assert result .returncode == 0
17+ assert "usage:" in result .stdout .lower ()
18+ assert "pygetpapers" in result .stdout
19+
20+
21+ def test_cli_version ():
22+ """Test that the CLI version command works"""
23+ result = subprocess .run ([sys .executable , "-m" , "pygetpapers.pygetpapers" , "--version" ],
24+ capture_output = True , text = True , timeout = 30 )
25+ assert result .returncode == 0
26+ assert "pygetpapers" in result .stdout .lower ()
27+
28+
29+ def test_cli_noexecute ():
30+ """Test the --noexecute flag (should not download anything)"""
31+ result = subprocess .run ([
32+ sys .executable , "-m" , "pygetpapers.pygetpapers" ,
33+ "-q" , "test query" ,
34+ "--noexecute" ,
35+ "-k" , "1"
36+ ], capture_output = True , text = True , timeout = 60 )
37+
38+ # Should complete without error (even if no results found)
39+ assert result .returncode in [0 , 1 ] # 0 = success, 1 = no results found
40+ assert "Total" in result .stdout or "hits" in result .stdout .lower ()
41+
42+
43+ def test_cli_syntax ():
44+ """Test that basic CLI syntax is valid"""
45+ # Test with invalid API (should fail gracefully)
46+ result = subprocess .run ([
47+ sys .executable , "-m" , "pygetpapers.pygetpapers" ,
48+ "--api" , "invalid_api" ,
49+ "-q" , "test" ,
50+ "--noexecute"
51+ ], capture_output = True , text = True , timeout = 30 )
52+
53+ # Should handle invalid API gracefully
54+ assert result .returncode != 0 # Should fail with invalid API
55+
56+
57+ def test_imports ():
58+ """Test that all main modules can be imported"""
59+ try :
60+ import pygetpapers
61+ import pygetpapers .pygetpapers
62+ print ("✅ All pygetpapers modules imported successfully" )
63+ except ImportError as e :
64+ assert False , f"Failed to import pygetpapers: { e } "
65+
66+
67+ def test_config_file ():
68+ """Test that config file exists and is readable"""
69+ config_path = Path ("pygetpapers/config.ini" )
70+ assert config_path .exists (), "config.ini should exist"
71+
72+ # Test that it can be read
73+ with open (config_path , 'r' ) as f :
74+ content = f .read ()
75+ assert "[DEFAULT]" in content or "api" in content .lower ()
76+
77+
78+ if __name__ == "__main__" :
79+ # Run all tests
80+ test_cli_help ()
81+ test_cli_version ()
82+ test_cli_noexecute ()
83+ test_cli_syntax ()
84+ test_imports ()
85+ test_config_file ()
86+ print ("✅ All CI tests passed!" )
0 commit comments