|
| 1 | +import assert from 'assert'; |
| 2 | +import { Uri } from 'vscode'; |
| 3 | +import { shouldProceedAfterPyprojectValidation, ValidationError } from '../../../managers/builtin/pipUtils'; |
| 4 | + |
| 5 | +suite('pipUtils - validatePyproject', () => { |
| 6 | + const mockValidationError: ValidationError = { |
| 7 | + message: 'Invalid package name "my package" in pyproject.toml.', |
| 8 | + fileUri: Uri.file('/test/path/pyproject.toml'), |
| 9 | + }; |
| 10 | + |
| 11 | + test('should return true when no validation error exists', async () => { |
| 12 | + // Arrange: no validation error |
| 13 | + const validationError = undefined; |
| 14 | + const install = ['-e', '/test/path']; |
| 15 | + |
| 16 | + // Act |
| 17 | + const result = await shouldProceedAfterPyprojectValidation(validationError, install); |
| 18 | + |
| 19 | + // Assert |
| 20 | + assert.strictEqual(result, true, 'Should proceed when no validation error'); |
| 21 | + }); |
| 22 | + |
| 23 | + test('should return true when install array is empty', async () => { |
| 24 | + // Arrange: validation error exists but no packages selected |
| 25 | + const install: string[] = []; |
| 26 | + |
| 27 | + // Act |
| 28 | + const result = await shouldProceedAfterPyprojectValidation(mockValidationError, install); |
| 29 | + |
| 30 | + // Assert |
| 31 | + assert.strictEqual(result, true, 'Should proceed when no packages selected'); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should return true when only requirements.txt packages selected (no -e flag)', async () => { |
| 35 | + // Arrange: validation error exists but only requirements.txt packages selected |
| 36 | + const install = ['-r', '/test/requirements.txt']; |
| 37 | + |
| 38 | + // Act |
| 39 | + const result = await shouldProceedAfterPyprojectValidation(mockValidationError, install); |
| 40 | + |
| 41 | + // Assert |
| 42 | + assert.strictEqual(result, true, 'Should proceed when no TOML packages selected'); |
| 43 | + }); |
| 44 | + |
| 45 | + test('should return true when only PyPI packages selected (no flags at all)', async () => { |
| 46 | + // Arrange: only PyPI package names, no flags |
| 47 | + const install = ['numpy', 'pandas', 'requests']; |
| 48 | + |
| 49 | + // Act |
| 50 | + const result = await shouldProceedAfterPyprojectValidation(mockValidationError, install); |
| 51 | + |
| 52 | + // Assert |
| 53 | + assert.strictEqual(result, true, 'Should proceed when only PyPI packages selected'); |
| 54 | + }); |
| 55 | + |
| 56 | + test('should not trigger on -e flag at end of array without following argument', async () => { |
| 57 | + // Arrange: -e flag is last item (malformed, but should not crash) |
| 58 | + const install = ['numpy', '-e']; |
| 59 | + // This is edge case - -e at end means no path follows, so index + 1 < arr.length is false |
| 60 | + |
| 61 | + // Act |
| 62 | + const result = await shouldProceedAfterPyprojectValidation(mockValidationError, install); |
| 63 | + |
| 64 | + // Assert |
| 65 | + assert.strictEqual(result, true, 'Should not crash on malformed -e flag at end'); |
| 66 | + }); |
| 67 | +}); |
0 commit comments