1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- import { expect , use } from 'chai' ;
5
- import * as fs from 'fs-extra' ;
6
- import * as path from 'path' ;
4
+ import { expect } from 'chai' ;
7
5
import * as TypeMoq from 'typemoq' ;
8
6
import { Container } from '../../../../node_modules/inversify' ;
9
- import { FileSystem } from '../../../client/common/platform/fileSystem' ;
10
7
import { PlatformService } from '../../../client/common/platform/platformService' ;
11
- import { ICurrentProcess , IFileSystem , IOperatingSystem , IPlatformService } from '../../../client/common/platform/types' ;
8
+ import { IOperatingSystem } from '../../../client/common/platform/types' ;
12
9
import { IPythonExecutionFactory , IPythonExecutionService } from '../../../client/common/process/types' ;
13
- import { IAnalysisSettings , IConfigurationService , IPythonSettings } from '../../../client/common/types' ;
10
+ import { IAnalysisSettings , IConfigurationService , ICurrentProcess , IPythonSettings } from '../../../client/common/types' ;
14
11
import { ServiceContainer } from '../../../client/ioc/container' ;
15
12
import { ServiceManager } from '../../../client/ioc/serviceManager' ;
16
- // tslint:disable-next-line:no-require-imports no-var-requires
17
- const assertArrays = require ( 'chai-arrays' ) ;
18
- use ( assertArrays ) ;
19
13
20
14
// tslint:disable-next-line:max-func-body-length
21
15
suite ( 'Platform' , ( ) => {
@@ -26,11 +20,12 @@ suite('Platform', () => {
26
20
let analysisSettings : TypeMoq . IMock < IAnalysisSettings > ;
27
21
let execFactory : TypeMoq . IMock < IPythonExecutionFactory > ;
28
22
let exec : TypeMoq . IMock < IPythonExecutionService > ;
23
+ let serviceManager : ServiceManager ;
29
24
let serviceContainer : ServiceContainer ;
30
25
31
26
setup ( ( ) => {
32
27
const cont = new Container ( ) ;
33
- const serviceManager = new ServiceManager ( cont ) ;
28
+ serviceManager = new ServiceManager ( cont ) ;
34
29
serviceContainer = new ServiceContainer ( cont ) ;
35
30
36
31
process = TypeMoq . Mock . ofType < ICurrentProcess > ( ) ;
@@ -41,9 +36,6 @@ suite('Platform', () => {
41
36
execFactory = TypeMoq . Mock . ofType < IPythonExecutionFactory > ( ) ;
42
37
exec = TypeMoq . Mock . ofType < IPythonExecutionService > ( ) ;
43
38
44
- serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
45
- serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
46
-
47
39
pythonSettings . setup ( x => x . analysis ) . returns ( ( ) => analysisSettings . object ) ;
48
40
config . setup ( x => x . getSettings ( TypeMoq . It . isAny ( ) ) ) . returns ( ( ) => pythonSettings . object ) ;
49
41
serviceManager . addSingletonInstance ( IConfigurationService , config . object ) ;
@@ -52,20 +44,55 @@ suite('Platform', () => {
52
44
serviceManager . addSingletonInstance ( IPythonExecutionFactory , execFactory . object ) ;
53
45
} ) ;
54
46
test ( 'Windows platform check' , async ( ) => {
47
+ process . setup ( x => x . platform ) . returns ( ( ) => 'win32' ) ;
48
+ serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
49
+ serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
55
50
const platform = new PlatformService ( serviceContainer ) ;
56
- process . setup ( x => x . platform ) . returns ( ( ) => 'win' ) ;
51
+
57
52
expect ( platform . isWindows ) . to . be . equal ( true , 'Platform must be Windows' ) ;
58
- expect ( platform . isMac ) . to . be . equal ( true , 'Platform must not be Mac' ) ;
59
- expect ( platform . isLinux ) . to . be . equal ( true , 'Platform must not be Linux' ) ;
53
+ expect ( platform . isMac ) . to . be . equal ( false , 'Platform must not be Mac' ) ;
54
+ expect ( platform . isLinux ) . to . be . equal ( false , 'Platform must not be Linux' ) ;
60
55
} ) ;
61
- test ( '32-bit platform check' , async ( ) => {
56
+ test ( 'Mac platform check' , async ( ) => {
57
+ process . setup ( x => x . platform ) . returns ( ( ) => 'darwin' ) ;
58
+ serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
59
+ serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
62
60
const platform = new PlatformService ( serviceContainer ) ;
61
+
62
+ expect ( platform . isMac ) . to . be . equal ( true , 'Platform must be Mac' ) ;
63
+ expect ( platform . isWindows ) . to . be . equal ( false , 'Platform must not be Windows' ) ;
64
+ expect ( platform . isLinux ) . to . be . equal ( false , 'Platform must not be Linux' ) ;
65
+ } ) ;
66
+ test ( '32-bit platform check' , async ( ) => {
63
67
os . setup ( x => x . arch ( ) ) . returns ( ( ) => '' ) ;
68
+ serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
69
+ serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
70
+ const platform = new PlatformService ( serviceContainer ) ;
71
+
64
72
expect ( platform . is64bit ) . to . be . equal ( false , 'Platform must not be x64' ) ;
65
73
} ) ;
66
74
test ( '64-bit platform check' , async ( ) => {
67
- const platform = new PlatformService ( serviceContainer ) ;
68
75
os . setup ( x => x . arch ( ) ) . returns ( ( ) => 'x64' ) ;
76
+ serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
77
+ serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
78
+ const platform = new PlatformService ( serviceContainer ) ;
79
+
69
80
expect ( platform . is64bit ) . to . be . equal ( true , 'Platform must be x64' ) ;
70
81
} ) ;
82
+ test ( 'bin/scripts check (Windows)' , async ( ) => {
83
+ process . setup ( x => x . platform ) . returns ( ( ) => 'win32' ) ;
84
+ serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
85
+ serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
86
+ const platform = new PlatformService ( serviceContainer ) ;
87
+
88
+ expect ( platform . virtualEnvBinName ) . to . be . equal ( 'scripts' , 'Venv bin must be scripts on Windows' ) ;
89
+ } ) ;
90
+ test ( 'bin/scripts check (Mac/Linux)' , async ( ) => {
91
+ process . setup ( x => x . platform ) . returns ( ( ) => 'darwin' ) ;
92
+ serviceManager . addSingletonInstance ( ICurrentProcess , process . object ) ;
93
+ serviceManager . addSingletonInstance ( IOperatingSystem , os . object ) ;
94
+ const platform = new PlatformService ( serviceContainer ) ;
95
+
96
+ expect ( platform . virtualEnvBinName ) . to . be . equal ( 'bin' , 'Venv bin must be scripts on Mac' ) ;
97
+ } ) ;
71
98
} ) ;
0 commit comments