Skip to content

Commit 07dc2fa

Browse files
author
MikhailArkhipov
committed
Platform tests
1 parent 2c7243c commit 07dc2fa

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

src/client/common/platform/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,3 @@ export interface IOperatingSystem {
6060
release(): string;
6161
arch(): string;
6262
}
63-
64-
export const ICurrentProcess = Symbol('ICurrentProcess');
65-
export interface ICurrentProcess {
66-
readonly platform: string;
67-
}
Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { expect, use } from 'chai';
5-
import * as fs from 'fs-extra';
6-
import * as path from 'path';
4+
import { expect } from 'chai';
75
import * as TypeMoq from 'typemoq';
86
import { Container } from '../../../../node_modules/inversify';
9-
import { FileSystem } from '../../../client/common/platform/fileSystem';
107
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';
129
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';
1411
import { ServiceContainer } from '../../../client/ioc/container';
1512
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);
1913

2014
// tslint:disable-next-line:max-func-body-length
2115
suite('Platform', () => {
@@ -26,11 +20,12 @@ suite('Platform', () => {
2620
let analysisSettings: TypeMoq.IMock<IAnalysisSettings>;
2721
let execFactory: TypeMoq.IMock<IPythonExecutionFactory>;
2822
let exec: TypeMoq.IMock<IPythonExecutionService>;
23+
let serviceManager: ServiceManager;
2924
let serviceContainer: ServiceContainer;
3025

3126
setup(() => {
3227
const cont = new Container();
33-
const serviceManager = new ServiceManager(cont);
28+
serviceManager = new ServiceManager(cont);
3429
serviceContainer = new ServiceContainer(cont);
3530

3631
process = TypeMoq.Mock.ofType<ICurrentProcess>();
@@ -41,9 +36,6 @@ suite('Platform', () => {
4136
execFactory = TypeMoq.Mock.ofType<IPythonExecutionFactory>();
4237
exec = TypeMoq.Mock.ofType<IPythonExecutionService>();
4338

44-
serviceManager.addSingletonInstance(ICurrentProcess, process.object);
45-
serviceManager.addSingletonInstance(IOperatingSystem, os.object);
46-
4739
pythonSettings.setup(x => x.analysis).returns(() => analysisSettings.object);
4840
config.setup(x => x.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object);
4941
serviceManager.addSingletonInstance(IConfigurationService, config.object);
@@ -52,20 +44,55 @@ suite('Platform', () => {
5244
serviceManager.addSingletonInstance(IPythonExecutionFactory, execFactory.object);
5345
});
5446
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);
5550
const platform = new PlatformService(serviceContainer);
56-
process.setup(x => x.platform).returns(() => 'win');
51+
5752
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');
6055
});
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);
6260
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 () => {
6367
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+
6472
expect(platform.is64bit).to.be.equal(false, 'Platform must not be x64');
6573
});
6674
test('64-bit platform check', async () => {
67-
const platform = new PlatformService(serviceContainer);
6875
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+
6980
expect(platform.is64bit).to.be.equal(true, 'Platform must be x64');
7081
});
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+
});
7198
});

src/test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ process.env.IS_MULTI_ROOT_TEST = IS_MULTI_ROOT_TEST.toString();
1818
// If running on CI server and we're running the debugger tests, then ensure we only run debug tests.
1919
// We do this to ensure we only run debugger test, as debugger tests are very flaky on CI.
2020
// So the solution is to run them separately and first on CI.
21-
const grep = IS_CI_SERVER && IS_CI_SERVER_TEST_DEBUGGER ? 'Debug' : undefined;
21+
const grep = IS_CI_SERVER && IS_CI_SERVER_TEST_DEBUGGER ? 'Debug' : 'Platform';
2222
const testFilesSuffix = process.env.TEST_FILES_SUFFIX;
2323

2424
// You can directly control Mocha options by uncommenting the following lines.

0 commit comments

Comments
 (0)