コード例 #1
0
        public void TestValidPipRequirements()
        {
            // add a package to the pip requirements
            var testRequirementFile = Path.Combine(PipPackagesTest.TestsPath, "test_requirements_2.txt");

            Assert.That(testRequirementFile, Does.Exist);
            string fileContents = File.ReadAllText(testRequirementFile);

            // To avoid uninstalling any packages, if a requirements file already exists,
            // base the test requirements on this file.
            if (m_pipRequirementsExists)
            {
                // TODO: what to test if toml is already installed at the expected version?
                Assert.That(m_origPipRequirementsContents, Does.Not.Contain("toml"), "Is toml already in your requirements.txt file?");
                fileContents += "\n" + m_origPipRequirementsContents;
            }
            Assert.That(fileContents, Is.Not.Null.Or.Empty);

            File.WriteAllText(PythonSettings.kPipRequirementsFile, fileContents);

            // reset on startup variable to simulate Unity starting up
            SessionState.SetBool(LoadPipRequirements.k_onStartup, true);

            LoadPipRequirements.LoadRequirements();

            var packageUpdateRegex = new Regex("The Project's following Python packages have been updated:.*");

            LogAssert.Expect(LogType.Log, packageUpdateRegex);

            // Check that toml was updated to 0.9.0
            var output = PipPackagesTest.CallPipFreeze();

            Assert.That(output, Does.Contain("toml==0.9.0\n"));

            // Test that the requirements are not reloaded again if they change (only loaded at startup)
            var newFileContents = m_pipRequirementsExists ? m_origPipRequirementsContents : "";

            File.WriteAllText(PythonSettings.kPipRequirementsFile, newFileContents);

            LoadPipRequirements.LoadRequirements();

            // toml should still be there as the requirements were not updated
            output = PipPackagesTest.CallPipFreeze();
            Assert.That(output, Does.Contain("toml==0.9.0\n"));
        }
コード例 #2
0
        public void TestNoPipRequirements()
        {
            // check that everything works without a requirements.txt file.
            if (m_pipRequirementsExists)
            {
                File.Delete(PythonSettings.kPipRequirementsFile);
            }
            Assert.That(PythonSettings.kPipRequirementsFile, Does.Not.Exist);

            var output = PipPackagesTest.CallPipFreeze();

            // reset on startup variable to simulate Unity starting up
            SessionState.SetBool(LoadPipRequirements.k_onStartup, true);
            LoadPipRequirements.LoadRequirements();

            // output of pip freeze should be the same
            Assert.That(PipPackagesTest.CallPipFreeze(), Is.EqualTo(output));
        }