示例#1
0
 def test_copy_empty_file(self, mock_os_fsync):
     flasher = FlasherMbed()
     with open("empty_file", 'a'):
         os.utime("empty_file", None)
     flasher.copy_file("empty_file", "target")
     os.remove("empty_file")
     os.remove("target")
     mock_os_fsync.assert_called_once()
示例#2
0
    def test_copy_empty_file_linux(self, mock_copy_file):
        flasher = FlasherMbed()
        with open("empty_file", 'a'):
            pass

        flasher.copy_file("empty_file", "target")
        os.remove("empty_file")
        mock_copy_file.assert_called_once_with(b"", "target")
示例#3
0
 def test_copy_empty_file_windows(self, mock_system):
     flasher = FlasherMbed()
     file_path = os.path.join(os.getcwd(), "empty_file")
     with open(file_path, 'a'):
         os.utime(file_path, None)
     flasher.copy_file(file_path, "target")
     os.remove(file_path)
     should_be = ["cmd", "/c", "copy", file_path, "target"]
     mock_system.assert_called_once_with(should_be)
示例#4
0
    def test_copy_file_flush_is_called(self, mock_os_fsync, mock_sha1,
                                       mock_open):
        flasher = FlasherMbed()
        flasher.copy_file("source_file", "destination")

        file_handle = mock_open.return_value.__enter__.return_value

        self.assertEqual(1, file_handle.flush.call_count)
        file_handle.flush.assert_called_once()
示例#5
0
    def test_copy_file_write_success(self, mock_os_fsync):
        flasher = FlasherMbed()
        with open("source_file", 'wb') as source_file:
            source_file.write(b"test data")

        flasher.copy_file("source_file", "destination")

        with open("destination", "rb") as destination:
            result = destination.read()

        # remove file before assert to clean environment
        os.remove("source_file")
        os.remove("destination")

        # make sure file.write() really worked
        self.assertEqual(result, b"test data", "copy file failed")
        mock_os_fsync.assert_called_once()
示例#6
0
 def test_copy_file_unable_to_read(self):
     flasher = FlasherMbed()
     with self.assertRaises(FlashError):
         flasher.copy_file("not-existing-file", "target")
示例#7
0
 def test_copy_file_with_spaces(self, mock_check_call):
     flasher = FlasherMbed()
     flasher.copy_file(__file__, "tar get")
     should_be = ["cmd", "/c", "copy", __file__, "tar get"]
     mock_check_call.assert_called_with(should_be)
示例#8
0
 def test_copy_file_with_spaces(self, mock_os_fsync):
     flasher = FlasherMbed()
     flasher.copy_file(__file__, "tar get")
     os.remove("tar get")
     mock_os_fsync.assert_called_once()
示例#9
0
 def test_copy_file_with_spaces(self, mock_system):
     flasher = FlasherMbed()
     flasher.copy_file(__file__, "tar get")
     should_be = 'copy "%s" "tar get"' % __file__
     mock_system.assert_called_once_with(should_be)