test_version.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/env python3
  2. """Integration tests for archivebox version command."""
  3. import os
  4. import subprocess
  5. import json
  6. import pytest
  7. from .fixtures import process, disable_extractors_dict
  8. class TestVersionQuiet:
  9. """Test the quiet/minimal version output."""
  10. def test_version_prints_version_number(self, tmp_path):
  11. """Test that version prints the version number."""
  12. os.chdir(tmp_path)
  13. result = subprocess.run(
  14. ['archivebox', 'version', '--quiet'],
  15. capture_output=True,
  16. text=True,
  17. )
  18. assert result.returncode == 0
  19. # Should contain a version string like "0.8.0" or similar
  20. version = result.stdout.strip()
  21. assert version
  22. # Version should be a valid semver-ish format
  23. parts = version.split('.')
  24. assert len(parts) >= 2 # At least major.minor
  25. def test_version_flag_prints_version_number(self, tmp_path):
  26. """Test that --version flag prints the version number."""
  27. os.chdir(tmp_path)
  28. result = subprocess.run(
  29. ['archivebox', '--version'],
  30. capture_output=True,
  31. text=True,
  32. )
  33. assert result.returncode == 0
  34. version = result.stdout.strip()
  35. assert version
  36. parts = version.split('.')
  37. assert len(parts) >= 2
  38. class TestVersionFull:
  39. """Test the full version output."""
  40. def test_version_shows_system_info(self, tmp_path, process):
  41. """Test that version shows system information."""
  42. os.chdir(tmp_path)
  43. result = subprocess.run(
  44. ['archivebox', 'version'],
  45. capture_output=True,
  46. text=True,
  47. )
  48. output = result.stdout
  49. # Should show basic system info (exit code may be 1 if binaries missing)
  50. assert 'ArchiveBox' in output
  51. def test_version_shows_binary_section(self, tmp_path, process):
  52. """Test that version shows binary dependencies section."""
  53. os.chdir(tmp_path)
  54. result = subprocess.run(
  55. ['archivebox', 'version'],
  56. capture_output=True,
  57. text=True,
  58. )
  59. output = result.stdout
  60. # Should show binary dependencies section
  61. assert 'Binary' in output or 'Dependenc' in output
  62. def test_version_shows_data_locations(self, tmp_path, process):
  63. """Test that version shows data locations."""
  64. os.chdir(tmp_path)
  65. result = subprocess.run(
  66. ['archivebox', 'version'],
  67. capture_output=True,
  68. text=True,
  69. )
  70. output = result.stdout
  71. # Should show data/code locations
  72. assert 'Data' in output or 'location' in output.lower() or 'DIR' in output or 'Code' in output
  73. class TestVersionWithBinaries:
  74. """Test version output after running install."""
  75. def test_version_shows_binary_status(self, tmp_path, process, disable_extractors_dict):
  76. """Test that version shows binary status (installed or not)."""
  77. os.chdir(tmp_path)
  78. # First run install (with dry-run to speed up)
  79. subprocess.run(
  80. ['archivebox', 'install', '--dry-run'],
  81. capture_output=True,
  82. text=True,
  83. env=disable_extractors_dict,
  84. )
  85. # Now check version
  86. result = subprocess.run(
  87. ['archivebox', 'version'],
  88. capture_output=True,
  89. text=True,
  90. env=disable_extractors_dict,
  91. )
  92. output = result.stdout
  93. # Should show binary status (either installed or not installed)
  94. assert 'installed' in output.lower() or 'Binary' in output
  95. class TestVersionCLI:
  96. """Test the CLI interface for version command."""
  97. def test_cli_help(self, tmp_path):
  98. """Test that --help works for version command."""
  99. os.chdir(tmp_path)
  100. result = subprocess.run(
  101. ['archivebox', 'version', '--help'],
  102. capture_output=True,
  103. text=True,
  104. )
  105. assert result.returncode == 0
  106. assert '--quiet' in result.stdout or '-q' in result.stdout
  107. def test_cli_invalid_option(self, tmp_path):
  108. """Test that invalid options are handled."""
  109. os.chdir(tmp_path)
  110. result = subprocess.run(
  111. ['archivebox', 'version', '--invalid-option'],
  112. capture_output=True,
  113. text=True,
  114. )
  115. # Should fail with non-zero exit code
  116. assert result.returncode != 0
  117. if __name__ == '__main__':
  118. pytest.main([__file__, '-v'])