|
1 | 1 | """Integration tests for HgClient checkout functionality""" |
2 | 2 |
|
3 | 3 | import os |
| 4 | +import subprocess |
4 | 5 | import tempfile |
5 | 6 | import unittest |
6 | 7 | from shutil import which |
@@ -61,5 +62,62 @@ def test_checkout_existing_directory(self): |
61 | 62 | ) |
62 | 63 |
|
63 | 64 |
|
| 65 | +@unittest.skipIf(not hg, '`hg` was not found') |
| 66 | +class TestExportRepository(unittest.TestCase): |
| 67 | + """Integration tests for HgClient _export_repository functionality.""" |
| 68 | + |
| 69 | + def setUp(self): |
| 70 | + """Set up test fixtures for each test""" |
| 71 | + self.test_dir = tempfile.mkdtemp(prefix='hg_test_') |
| 72 | + self.repo_path = os.path.join(self.test_dir, 'hello') |
| 73 | + self.export_base_path = os.path.join(self.test_dir, 'exported_repo') |
| 74 | + self.repo_url = 'https://www.mercurial-scm.org/repo/hello' |
| 75 | + |
| 76 | + self.hg_client = HgClient(self.repo_path) |
| 77 | + |
| 78 | + self._ensure_repo_cloned() |
| 79 | + |
| 80 | + def tearDown(self): |
| 81 | + """Clean up test fixtures""" |
| 82 | + if os.path.exists(self.test_dir): |
| 83 | + rmtree(self.test_dir) |
| 84 | + |
| 85 | + def _ensure_repo_cloned(self): |
| 86 | + """Ensure the test repository is cloned locally""" |
| 87 | + if not os.path.exists(self.repo_path): |
| 88 | + try: |
| 89 | + subprocess.run( |
| 90 | + ['hg', 'clone', '--rev', 'tip', self.repo_url, self.repo_path], |
| 91 | + check=True, |
| 92 | + capture_output=True, |
| 93 | + text=True, |
| 94 | + ) |
| 95 | + except subprocess.CalledProcessError as e: |
| 96 | + self.fail(f'Failed to clone repository: {e.stderr}') |
| 97 | + |
| 98 | + def test_export_repository_specific_revision(self): |
| 99 | + """Test exporting a specific revision""" |
| 100 | + result = self.hg_client._export_repository('1', self.export_base_path) |
| 101 | + self.assertTrue(result, "Export should succeed for revision '1'") |
| 102 | + |
| 103 | + # Verify files were created correctly |
| 104 | + tar_gz_path = self.export_base_path + '.tar.gz' |
| 105 | + self.assertTrue(os.path.exists(tar_gz_path)) |
| 106 | + |
| 107 | + def test_export_repository_invalid_revision(self): |
| 108 | + """Test exporting with an invalid revision""" |
| 109 | + invalid_revision = 'nonexistent123456789' |
| 110 | + |
| 111 | + result = self.hg_client._export_repository( |
| 112 | + invalid_revision, self.export_base_path |
| 113 | + ) |
| 114 | + self.assertFalse(result, 'Export should fail for invalid revision') |
| 115 | + |
| 116 | + tar_gz_path = self.export_base_path + '.tar.gz' |
| 117 | + tar_path = self.export_base_path + '.tar' |
| 118 | + self.assertFalse(os.path.exists(tar_gz_path)) |
| 119 | + self.assertFalse(os.path.exists(tar_path)) |
| 120 | + |
| 121 | + |
64 | 122 | if __name__ == '__main__': |
65 | 123 | unittest.main() |
0 commit comments