Exemplo n.º 1
0
    def test_can_Write_string_in_append_mode(self, mock_output):
        file = FakeFile(self.salutation, mode='a')
        mock_output.return_value = file
        question = ' How are you?'
        action = Write(self.absfilepath, question, append=True)
        action.perform(should_raise=True)
        action.perform()

        self.assertEqual(self.salutation + question + '\n' + question + '\n',
                         file.read())
Exemplo n.º 2
0
    def test_Write_does_not_raise_when_instantiated_with_unexpected_types(
            self):
        write1 = Write(self.absfilepath, to_write='data', prefix='prefix')
        self.assertIsInstance(write1, Write)

        write2 = Write(self.absfilepath, to_write=123, prefix='prefix')
        self.assertIsInstance(write2, Action.Construct)
        result2 = write2.perform()
        self.assertIsInstance(result2, Result)
        self.assertIsInstance(result2.value, TypeError)

        write3 = Write(self.absfilepath, to_write='123', prefix=123)
        self.assertIsInstance(write3, Action.Construct)
        result3 = write3.perform()
        self.assertIsInstance(result3, Result)
        self.assertIsInstance(result3.value, TypeError)
Exemplo n.º 3
0
    def test_can_make_directory_on_Write(self, mock_open, mock_exists,
                                         mock_mkdir):
        declaration = "I don't want him hurt."
        exclamation = " Jurgal's animal is insane!"
        file = FakeFile(declaration, mode='a')
        mock_mkdir.return_value = None
        mock_exists.side_effect = [False, True]
        mock_open.return_value = file
        filename = 'directory/file'
        action = Write(filename=filename,
                       to_write=exclamation,
                       overwrite=True,
                       mkdir=True)
        result = action.perform()

        self.assertTrue(action.path.parent.exists())
        self.assertTrue(result.successful)
Exemplo n.º 4
0
 def test_cannot_Write_to_directory(self):
     write = Write(str(Path(__file__).parent), to_write='something')
     with self.assertRaises(IsADirectoryError):
         write.perform(should_raise=True)