public void Term()
 {
     if (m_pipRequirementsExists)
     {
         // make sure original requirements are reset
         File.WriteAllText(PythonSettings.kPipRequirementsFile, m_origPipRequirementsContents);
         SessionState.SetBool(LoadPipRequirements.k_onStartup, true);
         LoadPipRequirements.LoadRequirements();
     }
     else
     {
         // delete file as it didn't exist before the tests ran.
         File.Delete(PythonSettings.kPipRequirementsFile);
     }
 }
        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"));
        }
        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));
        }