예제 #1
0
    def test_write_requirements__simple(self, mock_path_exists, mock_open,
                                        mock_write):
        """
        TestShakerMetadata: Test resolved dependency are correctly written out to file
        """

        # Setup
        testobj = ShakerRemote(self._sample_dependencies)
        output_directory = "tests/files"
        output_filename = "test_dependencies.txt"
        output_path = '%s/%s' % (output_directory, output_filename)

        # Simple write
        mock_path_exists.return_value = False
        testobj.write_requirements(output_directory,
                                   output_filename,
                                   overwrite=False,
                                   backup=False)
        mock_open.assert_called_once_with(output_path, 'w')
        mock_write.assert_called_once(self._sample_requirements)
예제 #2
0
    def test_write_requirements__overwrite(self, mock_path_exists, mock_open,
                                           mock_write):
        """
        TestShakerMetadata: Test resolved dependency overwrites an existing file when forced
        """

        # Setup
        testobj = ShakerRemote(self._sample_dependencies)
        output_directory = "tests/files"
        output_filename = "test_dependencies.txt"
        output_path = '%s/%s' % (output_directory, output_filename)

        # Overwrite an existing file
        mock_path_exists.return_value = True
        testobj.write_requirements(output_directory,
                                   output_filename,
                                   overwrite=True,
                                   backup=False)
        mock_open.assert_called_once_with(output_path, 'w')
        mock_write.assert_called_once(self._sample_requirements)
예제 #3
0
    def test_write_requirements__no_overwrite(self, mock_path_exists,
                                              mock_open, mock_write):
        """
        TestShakerMetadata: Test resolved dependency do not overwrite an existing file
        """

        # Setup
        testobj = ShakerRemote(self._sample_dependencies)
        output_filename = "test_dependencies.txt"

        # Don't overwrite an existing file
        mock_path_exists.return_value = True
        testobj.write_requirements(output_filename,
                                   overwrite=False,
                                   backup=False)
        self.assertFalse(mock_open.called,
                         ("With overwrite disabled, "
                          "we shouldn't have called to open"))
        self.assertFalse(mock_write.called,
                         ("With overwrite disabled, "
                          "we shouldn't have called to write"))
예제 #4
0
    def test_write_requirements__no_overwrite(self,
                                              mock_path_exists,
                                              mock_open,
                                              mock_write):
        """
        TestShakerMetadata: Test resolved dependency do not overwrite an existing file
        """

        # Setup
        testobj = ShakerRemote(self._sample_dependencies)
        output_filename = "test_dependencies.txt"

        # Don't overwrite an existing file
        mock_path_exists.return_value = True
        testobj.write_requirements(output_filename,
                                   overwrite=False,
                                   backup=False)
        self.assertFalse(mock_open.called, ("With overwrite disabled, "
                                            "we shouldn't have called to open"))
        self.assertFalse(mock_write.called, ("With overwrite disabled, "
                                             "we shouldn't have called to write"))
예제 #5
0
    def test_write_requirements__simple(self,
                                        mock_path_exists,
                                        mock_open,
                                        mock_write):
        """
        TestShakerMetadata: Test resolved dependency are correctly written out to file
        """

        # Setup
        testobj = ShakerRemote(self._sample_dependencies)
        output_directory = "tests/files"
        output_filename = "test_dependencies.txt"
        output_path = '%s/%s' % (output_directory,
                                 output_filename)

        # Simple write
        mock_path_exists.return_value = False
        testobj.write_requirements(output_directory,
                                   output_filename,
                                   overwrite=False,
                                   backup=False)
        mock_open.assert_called_once_with(output_path, 'w')
        mock_write.assert_called_once(self._sample_requirements)
예제 #6
0
    def test_write_requirements__overwrite(self,
                                           mock_path_exists,
                                           mock_open,
                                           mock_write):
        """
        TestShakerMetadata: Test resolved dependency overwrites an existing file when forced
        """

        # Setup
        testobj = ShakerRemote(self._sample_dependencies)
        output_directory = "tests/files"
        output_filename = "test_dependencies.txt"
        output_path = '%s/%s' % (output_directory,
                                 output_filename)

        # Overwrite an existing file
        mock_path_exists.return_value = True
        testobj.write_requirements(output_directory,
                                   output_filename,
                                   overwrite=True,
                                   backup=False)
        mock_open.assert_called_once_with(output_path, 'w')
        mock_write.assert_called_once(self._sample_requirements)