1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT License.
3+
4+ import { mock } from 'ts-mockito' ;
5+ import { expect } from 'chai' ;
6+ import { UvInstaller } from './uvInstaller.node' ;
7+ import { IServiceContainer } from '../../ioc/types' ;
8+ import { ModuleInstallerType , ModuleInstallFlags } from './types' ;
9+ import { EnvironmentType , PythonEnvironment } from '../../pythonEnvironments/info' ;
10+ import { Environment } from '@vscode/python-extension' ;
11+
12+ // Mock helper to simulate getEnvironmentType
13+ const mockGetEnvironmentType = ( envType : EnvironmentType ) => {
14+ // This would need to be properly mocked in a real test environment
15+ return envType ;
16+ } ;
17+
18+ describe ( 'UV Installer' , ( ) => {
19+ let installer : UvInstaller ;
20+ let serviceContainer : IServiceContainer ;
21+
22+ beforeEach ( ( ) => {
23+ serviceContainer = mock < IServiceContainer > ( ) ;
24+ installer = new UvInstaller ( serviceContainer ) ;
25+ } ) ;
26+
27+ it ( 'Should have correct properties' , ( ) => {
28+ expect ( installer . name ) . to . equal ( 'UV' ) ;
29+ expect ( installer . displayName ) . to . equal ( 'UV' ) ;
30+ expect ( installer . type ) . to . equal ( ModuleInstallerType . UV ) ;
31+ expect ( installer . priority ) . to . equal ( 10 ) ;
32+ } ) ;
33+
34+ it ( 'Should support UV environments' , async ( ) => {
35+ const mockInterpreter : PythonEnvironment = {
36+ id : 'test-uv-env' ,
37+ uri : { fsPath : '/path/to/uv/env' } as any
38+ } ;
39+
40+ // This test would need to be enhanced with proper mocking
41+ // For now, it demonstrates the expected structure
42+ expect ( installer . isSupported ) . to . be . a ( 'function' ) ;
43+ } ) ;
44+
45+ it ( 'Should generate correct execution args for UV pip install' , async ( ) => {
46+ const mockInterpreter : Environment = {
47+ id : 'test-uv-env' ,
48+ path : '/path/to/uv/env' ,
49+ tools : [ 'uv' ] ,
50+ } as any ;
51+
52+ // Test basic installation
53+ const args = await ( installer as any ) . getExecutionArgs ( 'numpy' , mockInterpreter , ModuleInstallFlags . None ) ;
54+
55+ expect ( args . exe ) . to . equal ( 'uv' ) ;
56+ expect ( args . args ) . to . include ( 'pip' ) ;
57+ expect ( args . args ) . to . include ( 'install' ) ;
58+ expect ( args . args ) . to . include ( 'numpy' ) ;
59+ } ) ;
60+
61+ it ( 'Should handle upgrade flag correctly' , async ( ) => {
62+ const mockInterpreter : Environment = {
63+ id : 'test-uv-env' ,
64+ path : '/path/to/uv/env' ,
65+ tools : [ 'uv' ] ,
66+ } as any ;
67+
68+ const args = await ( installer as any ) . getExecutionArgs ( 'numpy' , mockInterpreter , ModuleInstallFlags . upgrade ) ;
69+
70+ expect ( args . args ) . to . include ( '--upgrade' ) ;
71+ } ) ;
72+
73+ it ( 'Should handle reinstall flag correctly' , async ( ) => {
74+ const mockInterpreter : Environment = {
75+ id : 'test-uv-env' ,
76+ path : '/path/to/uv/env' ,
77+ tools : [ 'uv' ] ,
78+ } as any ;
79+
80+ const args = await ( installer as any ) . getExecutionArgs ( 'numpy' , mockInterpreter , ModuleInstallFlags . reInstall ) ;
81+
82+ expect ( args . args ) . to . include ( '--force-reinstall' ) ;
83+ } ) ;
84+ } ) ;
0 commit comments