예제 #1
0
 def test_csproj_get_assembly_version(self):
     """Test CsProj.get_assembly_version - returns assembly version path from a csproj / AssemblyInfo file """
     with temp_dir() as tmp_root_dir:
         csproj_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), csproj_root)
         csproj = CsProj(os.path.join(csproj_root, _TEST_CSPROJ))
         assert csproj.get_assembly_version() == "1.2.3"
예제 #2
0
 def test_csproj_get_assembly_name(self):
     """Test CsProj.get_assembly_name - returns assembly name from a csproj file """
     with temp_dir() as tmp_root_dir:
         csproj_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), csproj_root)
         csproj = CsProj(os.path.join(csproj_root, _TEST_CSPROJ))
         assert csproj.get_assembly_name() == "MyProject"
예제 #3
0
 def test_csproj_get_csproj_at_path_when_path_contains_csproj(self):
     """Test CsProj.get_csproj_at_path - returns path if path is a file"""
     file_name = "MyProject.csproj"
     with temp_dir() as tmp_root_dir:
         path = os.path.normpath(os.path.join(tmp_root_dir, file_name))
         create_empty_file(path)
         assert CsProj.get_csproj_at_path(tmp_root_dir) == path
예제 #4
0
 def test_csproj_path_is_csproj_file(self):
     """Test CsProj.path_is_csproj_file - returns true path is a .csproj file"""
     file_name = "MyProject.csproj"
     with temp_dir() as tmp_root_dir:
         path = os.path.normpath(os.path.join(tmp_root_dir, file_name))
         create_empty_file(path)
         assert CsProj.path_is_csproj_file(path)
예제 #5
0
    def test_utils_copy_replace_directory(self):
        """Test utils.copy_replace_directory """
        with temp_dir() as tmp_dir_path:
            dir_old = os.path.normpath("old/path")
            dir_new = os.path.normpath("new/path")
            file_name = "my_file.txt"
            old_dir_path = os.path.join(tmp_dir_path, dir_old)
            new_dir_path = os.path.join(tmp_dir_path, dir_new)
            old_file_path = os.path.normpath(
                os.path.join(old_dir_path, file_name))
            new_file_path = os.path.normpath(
                os.path.join(new_dir_path, file_name))
            os.makedirs(old_dir_path)
            os.makedirs(new_dir_path)

            with open(old_file_path, "w+") as f:
                f.write("Old Text")

            with open(new_file_path, "w+") as f:
                f.write("New Text")

            copy_replace_directory(new_dir_path, old_dir_path)

            with open(old_file_path, "r") as f:
                old_text = f.read()
                assert old_text == "New Text", "Text did not get replaced."

            with open(new_file_path, "r") as f:
                old_text = f.read()
                assert old_text == "New Text", "Wrong file was replaced."
예제 #6
0
 def test_nuspec_path_is_nuspec_file(self):
     """Test NuSpec.get_nuspec_at_path when path is a nuspec file"""
     with temp_dir() as tmp_root_dir:
         nuspec_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), nuspec_root)
         nuspec_path = os.path.join(nuspec_root, _TEST_NUSPEC)
         assert NuSpec.path_is_nuspec_file(nuspec_path)
예제 #7
0
 def test_csproj_get_output_path(self):
     """Test CsProj.get_output_path - returns csproj output path from a csproj file """
     with temp_dir() as tmp_root_dir:
         csproj_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), csproj_root)
         csproj = CsProj(os.path.join(csproj_root, _TEST_CSPROJ))
         assert csproj.get_output_path("Debug") == "bin/Debug/"
         assert csproj.get_output_path("Release") == "bin/Release/"
예제 #8
0
 def test_nuspec_get_package_version(self):
     """Test NuSpec.get_package_version """
     with temp_dir() as tmp_root_dir:
         nuspec_root = os.path.join(tmp_root_dir, "test")
         shutil.copytree(get_fixture_dir(), nuspec_root)
         nuspec_path = os.path.join(nuspec_root, _TEST_NUSPEC)
         nuspec = NuSpec(nuspec_path)
         assert nuspec.get_package_version(
         ) == "1.0.0"  # Set to "1.0.0" in fixture .nuspec file
예제 #9
0
 def test_msbuild_runner_locate_msbuild_when_dotnet_framework_installed_win32(self, mock_call, mock_sys):
     """Test MsBuildRunner.locate_msbuild - returns msbuild path in the local system using .NET Framework path """
     if sys.platform != 'win32': # TODO: Fix unit test compatibility on non-windows platform
         return
     mock_call.return_value = 0
     mock_sys.configure_mock(platform='win32')
     vs_msbuild_dir = os.path.normpath("Microsoft.NET\\Framework\\1.0\\")
     msbuild_name = "MSBuild.exe"
     with temp_dir() as tmp_root_dir:
         from ugetcli import msbuild
         with patch.dict(msbuild.os.environ, {'ProgramFiles': tmp_root_dir, 'WINDIR': tmp_root_dir}, clear=True):
             msbuild_dir_path = os.path.join(tmp_root_dir, vs_msbuild_dir)
             os.makedirs(msbuild_dir_path)
             msbuild_path = os.path.join(msbuild_dir_path, msbuild_name)
             create_empty_file(msbuild_path)
             assert MsBuildRunner.locate_msbuild() == msbuild_path
예제 #10
0
 def test_msbuild_build_with_rebuild(self, mock_popen, mock_escape_exe_path):
     """Test MsBuildRunner.build - rebuilds .csproj """
     mock_process_instance = MagicMock()
     mock_popen.return_value = mock_process_instance
     mock_process_instance.wait.return_value = 0
     mock_escape_exe_path.return_value = "msbuild.exe"
     with temp_dir() as tmp_root_dir:
         msbuild_path = os.path.join(tmp_root_dir, "msbuild.exe")
         project_path = os.path.join(tmp_root_dir, "Project.csproj")
         create_empty_file(msbuild_path)
         create_empty_file(project_path)
         configuration = "Debug"
         msbuild = MsBuildRunner(msbuild_path)
         msbuild.build(project_path, configuration, True)
         expected_command = 'msbuild.exe {project_path} /t:Clean,Build /p:"Configuration={configuration}" /p:"DebugType=full"' \
                            ' /verbosity:{verbosity}'.format(project_path=project_path, configuration=configuration,
                                                             verbosity="minimal")
         mock_popen.assert_called_with(expected_command, shell=True)
         mock_process_instance.wait.assert_called()