def test_print_folder_should_raise_exception_when_no_gcode_files(self,  mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     mock_isdir.return_value = True
     with patch('peachyprinter.api.print_api.listdir', return_value=['ASDFAS.txt', 'bor.fa']):
         with self.assertRaises(Exception):
             api = PrintQueueAPI(self.default_config)
             api.print_folder(folder)
Exemple #2
0
 def test_print_folder_should_delay_between_prints(self, mock_PrintAPI,
                                                   mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     expected_file2 = 'thingy2.gcode'
     expected_delay = 0.1
     mock_isdir.return_value = True
     config = self.default_config
     config.options.print_queue_delay = expected_delay
     with patch('peachyprinter.api.print_api.listdir',
                return_value=[
                    'ASDFAS.txt', 'bor.fa', expected_file1, expected_file2
                ]):
         api = PrintQueueAPI(config)
         api.print_folder(folder)
         self.assertEquals(1, mock_PrintAPI.call_count)
         call_back = mock_PrintAPI.call_args[0][1]
         start = time.time()
         mock_status = {'status': 'Complete'}
         call_back(mock_status)
         call_back(mock_status)
         end = time.time()
         self.assertTrue(
             expected_delay <= end - start + 0.01,
             "%s was not <= %s" % (expected_delay, (end - start + 0.01)))
 def test_print_folder_should_call_print_api_for_gcode_files(self, mock_print_gcode, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file = 'thingy.gcode'
     expected_path = os.path.join(folder, expected_file)
     mock_isdir.return_value = True
     with patch('peachyprinter.api.print_api.listdir', return_value=['ASDFAS.txt', 'bor.fa', expected_file]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
     mock_print_gcode.assert_called_with(expected_path)
    def test_print_folder_should_raise_exception_when_folder_is_empty(self, mock_isdir):
        folder = os.path.join('SomthingMadeUp')
        mock_isdir.return_value = False

        with self.assertRaises(Exception):
            api = PrintQueueAPI(self.default_config)
            api.print_folder(folder)

        mock_isdir.assert_called_with(folder)
Exemple #5
0
 def test_print_folder_should_raise_exception_when_no_gcode_files(
         self, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     mock_isdir.return_value = True
     with patch('peachyprinter.api.print_api.listdir',
                return_value=['ASDFAS.txt', 'bor.fa']):
         with self.assertRaises(Exception):
             api = PrintQueueAPI(self.default_config)
             api.print_folder(folder)
 def test_print_folder_ends_smoothly(self, mock_PrintAPI, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     mock_isdir.return_value = True
     with patch('peachyprinter.api.print_api.listdir', return_value=['ASDFAS.txt', 'bor.fa', expected_file1]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
         call_back = mock_PrintAPI.call_args[0][1]
         mock_status = {'status': 'Complete'}
         call_back(mock_status)
Exemple #7
0
    def test_print_folder_should_raise_exception_when_folder_is_empty(
            self, mock_isdir):
        folder = os.path.join('SomthingMadeUp')
        mock_isdir.return_value = False

        with self.assertRaises(Exception):
            api = PrintQueueAPI(self.default_config)
            api.print_folder(folder)

        mock_isdir.assert_called_with(folder)
Exemple #8
0
 def test_print_folder_should_call_print_api_for_gcode_files(
         self, mock_print_gcode, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file = 'thingy.gcode'
     expected_path = os.path.join(folder, expected_file)
     mock_isdir.return_value = True
     with patch('peachyprinter.api.print_api.listdir',
                return_value=['ASDFAS.txt', 'bor.fa', expected_file]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
     mock_print_gcode.assert_called_with(expected_path)
Exemple #9
0
 def test_print_folder_ends_smoothly(self, mock_PrintAPI, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     mock_isdir.return_value = True
     with patch('peachyprinter.api.print_api.listdir',
                return_value=['ASDFAS.txt', 'bor.fa', expected_file1]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
         call_back = mock_PrintAPI.call_args[0][1]
         mock_status = {'status': 'Complete'}
         call_back(mock_status)
 def test_print_folder_should_be_interuptable(self, mock_PrintAPI, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     expected_file2 = 'thingy2.gcode'
     mock_isdir.return_value = True
     mock_print_api = mock_PrintAPI.return_value
     with patch('peachyprinter.api.print_api.listdir', return_value=['ASDFAS.txt', 'bor.fa', expected_file1, expected_file2]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
         api.close()
         mock_print_api.close.assert_called_with()
         self.assertEquals(1, mock_PrintAPI.call_count)
 def test_print_folder_should_close_api_before_opening_new_one(self, mock_PrintAPI, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     expected_file2 = 'thingy2.gcode'
     mock_isdir.return_value = True
     mock_print_api = mock_PrintAPI.return_value
     with patch('peachyprinter.api.print_api.listdir', return_value=['ASDFAS.txt', 'bor.fa', expected_file1, expected_file2]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
         call_back = mock_PrintAPI.call_args[0][1]
         mock_status = {'status': 'Complete'}
         call_back(mock_status)
         mock_print_api.close.assert_called_with()
Exemple #12
0
 def test_print_folder_should_be_interuptable(self, mock_PrintAPI,
                                              mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     expected_file2 = 'thingy2.gcode'
     mock_isdir.return_value = True
     mock_print_api = mock_PrintAPI.return_value
     with patch('peachyprinter.api.print_api.listdir',
                return_value=[
                    'ASDFAS.txt', 'bor.fa', expected_file1, expected_file2
                ]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
         api.close()
         mock_print_api.close.assert_called_with()
         self.assertEquals(1, mock_PrintAPI.call_count)
Exemple #13
0
 def test_print_folder_should_close_api_before_opening_new_one(
         self, mock_PrintAPI, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     expected_file2 = 'thingy2.gcode'
     mock_isdir.return_value = True
     mock_print_api = mock_PrintAPI.return_value
     with patch('peachyprinter.api.print_api.listdir',
                return_value=[
                    'ASDFAS.txt', 'bor.fa', expected_file1, expected_file2
                ]):
         api = PrintQueueAPI(self.default_config)
         api.print_folder(folder)
         call_back = mock_PrintAPI.call_args[0][1]
         mock_status = {'status': 'Complete'}
         call_back(mock_status)
         mock_print_api.close.assert_called_with()
 def test_print_folder_should_delay_between_prints(self, mock_PrintAPI, mock_isdir):
     folder = os.path.join('', 'SomthingMadeUp')
     expected_file1 = 'thingy1.gcode'
     expected_file2 = 'thingy2.gcode'
     expected_delay = 0.1
     mock_isdir.return_value = True
     config = self.default_config
     config.options.print_queue_delay = expected_delay
     with patch('peachyprinter.api.print_api.listdir', return_value=['ASDFAS.txt', 'bor.fa', expected_file1, expected_file2]):
         api = PrintQueueAPI(config)
         api.print_folder(folder)
         self.assertEquals(1, mock_PrintAPI.call_count)
         call_back = mock_PrintAPI.call_args[0][1]
         start = time.time()
         mock_status = {'status': 'Complete'}
         call_back(mock_status)
         call_back(mock_status)
         end = time.time()
         self.assertTrue(expected_delay <= end-start + 0.01, "%s was not <= %s" % (expected_delay, (end - start + 0.01)))