def vswhere_path_test(self): """ Locate vswhere in PATH or in ProgramFiles """ # vswhere not found with tools.environment_append({"ProgramFiles": None, "ProgramFiles(x86)": None, "PATH": ""}): with six.assertRaisesRegex(self, ConanException, "Cannot locate vswhere"): vswhere() # vswhere in ProgramFiles but not in PATH program_files = get_env("ProgramFiles(x86)") or get_env("ProgramFiles") vswhere_path = None if program_files: expected_path = os.path.join(program_files, "Microsoft Visual Studio", "Installer", "vswhere.exe") if os.path.isfile(expected_path): vswhere_path = expected_path with tools.environment_append({"PATH": ""}): self.assertTrue(vswhere()) # vswhere in PATH but not in ProgramFiles env = {"ProgramFiles": None, "ProgramFiles(x86)": None} if not which("vswhere") and vswhere_path: vswhere_folder = os.path.join(program_files, "Microsoft Visual Studio", "Installer") env.update({"PATH": [vswhere_folder]}) with tools.environment_append(env): self.assertTrue(vswhere())
def vswhere_description_strip_test(self): myoutput = """ [ { "instanceId": "17609d7c", "installDate": "2018-06-11T02:15:04Z", "installationName": "VisualStudio/15.7.3+27703.2026", "installationPath": "", "installationVersion": "15.7.27703.2026", "productId": "Microsoft.VisualStudio.Product.Enterprise", "productPath": "", "isPrerelease": false, "displayName": "Visual Studio Enterprise 2017", "description": "生産性向上と、さまざまな規模のチーム間の調整のための Microsoft DevOps ソリューション", "channelId": "VisualStudio.15.Release", "channelUri": "https://aka.ms/vs/15/release/channel", "enginePath": "", "releaseNotes": "https://go.microsoft.com/fwlink/?LinkId=660692#15.7.3", "thirdPartyNotices": "https://go.microsoft.com/fwlink/?LinkId=660708", "updateDate": "2018-06-11T02:15:04.7009868Z", "catalog": { "buildBranch": "d15.7", "buildVersion": "15.7.27703.2026", "id": "VisualStudio/15.7.3+27703.2026", "localBuild": "build-lab", "manifestName": "VisualStudio", "manifestType": "installer", "productDisplayVersion": "15.7.3", "productLine": "Dev15", "productLineVersion": "2017", "productMilestone": "RTW", "productMilestoneIsPreRelease": "False", "productName": "Visual Studio", "productPatchVersion": "3", "productPreReleaseMilestoneSuffix": "1.0", "productRelease": "RTW", "productSemanticVersion": "15.7.3+27703.2026", "requiredEngineVersion": "1.16.1187.57215" }, "properties": { "campaignId": "", "canceled": "0", "channelManifestId": "VisualStudio.15.Release/15.7.3+27703.2026", "nickname": "", "setupEngineFilePath": "" } }, { "instanceId": "VisualStudio.12.0", "installationPath": "", "installationVersion": "12.0" } ] """ if six.PY3: # In python3 the output from subprocess.check_output are bytes, not str myoutput = myoutput.encode() myrunner = mock_open() myrunner.check_output = lambda x: myoutput with patch('conans.client.tools.win.subprocess', myrunner): json = vswhere() self.assertNotIn("descripton", json)