def test_get_cure_test_returns_a_layer_generator(self, mock_load):
     mock_load.return_value = self.DEFAULT_CONFIG
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     cure_test = configuration_API.get_cure_test(0,1,1,2)
     cure_test.next()
    def test_get_available_audio_options_should_include_recomended_options(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [{'sample_rate' : 48000, 'depth': '16 bit' }], 
            "output": [{'sample_rate' : 48000, 'depth': '16 bit' }]
            }
        
        expected_in  = AudioSetting(48000,'16 bit', current = True)
        expected_in.set_recommended()
        expected_out = AudioSetting(48000,'16 bit', current = True)
        expected_out.set_recommended()
        

        expected = {
                    "inputs" : [expected_in], 
                    "outputs": [expected_out] 
                   }

        mock_get_valid_sampling_options.return_value = audio_options
        mock_load.return_value = self.DEFAULT_CONFIG
        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer("Printer")
        
        actual = capi.get_available_audio_options()

        self.assertListContentsEqual(expected['inputs'],actual['inputs'])
        self.assertListContentsEqual(expected['outputs'],actual['outputs'])
 def test_get_speed_at_height_returns_a_correct_height(self, mock_load):
     mock_load.return_value = self.DEFAULT_CONFIG
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     speed = configuration_API.get_speed_at_height(0,1,10,20,0.5)
     self.assertEquals(15, speed)
 def test_get_cure_test_returns_a_layer_generator(self, mock_load):
     mock_load.return_value = self.default_config
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     cure_test = configuration_API.get_cure_test(0,1,1,2)
     cure_test.next()
    def test_get_available_audio_options_should_include_recomended_options(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [{'sample_rate' : 48000, 'depth': '16 bit' }], 
            "output": [{'sample_rate' : 48000, 'depth': '16 bit' }]
            }
        
        expected_in  = AudioSetting(48000,'16 bit', current = True)
        expected_in.set_recommended()
        expected_out = AudioSetting(48000,'16 bit', current = True)
        expected_out.set_recommended()
        

        expected = {
                    "inputs" : [expected_in], 
                    "outputs": [expected_out] 
                   }

        mock_get_valid_sampling_options.return_value = audio_options
        mock_load.return_value = self.default_config
        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer("Printer")
        
        actual = capi.get_available_audio_options()

        self.assertListContentsEqual(expected['inputs'],actual['inputs'])
        self.assertListContentsEqual(expected['outputs'],actual['outputs'])
    def test_get_available_audio_options_sets_currently_selected(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [{'sample_rate' : 48000, 'depth': '16 bit' },{'sample_rate' : 44100, 'depth': '16 bit' }], 
            "output": [{'sample_rate' : 48000, 'depth': '16 bit' },{'sample_rate' : 44100, 'depth': '16 bit' }]
            }

        mock_get_valid_sampling_options.return_value = audio_options
        config = self.default_config
        config.audio.input.bit_depth = '16 bit'
        config.audio.input.sample_rate = 44100
        config.audio.output.bit_depth = '16 bit'
        config.audio.output.sample_rate = 44100

        mock_load.return_value = config

        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer("Printer")

        actual = capi.get_available_audio_options()

        in1 = AudioSetting(44100,'16 bit', current = True)
        in2 = AudioSetting(48000,'16 bit', recommended = True)
        out1 = AudioSetting(44100,'16 bit', current = True)
        out2 = AudioSetting(48000,'16 bit', recommended = True)
        

        self.assertListContentsEqual([in1, in2],actual['inputs'])
        self.assertListContentsEqual([out1, out2],actual['outputs'])
class AddPrinterUI(PeachyFrame):
    def initialize(self):
        self.grid()
        self._configuration_api = ConfigurationAPI(self._configuration_manager)
        
        self._printer_name = StringVar()

        Label(self, text = "Enter a name for your printer" ).grid(column=0,row=10)
        Entry(self, textvariable = self._printer_name).grid(column=1, row=10)

        Label(self).grid(column=1,row=20)

        Button(self, text ="Save", command = self._save).grid(column=1,row=30, sticky=N+S+E)
        Button(self,text=u"Cancel", command=self._back).grid(column=0,row=100)

        self.update()

    def _save(self):
        printer_name = self._printer_name.get()
        self._configuration_api.add_printer(printer_name)
        self.navigate(SetupUI)
        
    def _back(self):
        self.navigate(SetupUI)

    def close(self):
        pass
 def test_get_speed_at_height_returns_a_correct_height(self, mock_load):
     mock_load.return_value = self.default_config
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     speed = configuration_API.get_speed_at_height(0,1,10,20,0.5)
     self.assertEquals(15, speed)
class AddPrinterUI(PeachyFrame):
    def initialize(self):
        self.grid()
        self._configuration_api = ConfigurationAPI(self._configuration_manager)

        self._printer_name = StringVar()

        Label(self, text="Enter a name for your printer").grid(column=0,
                                                               row=10)
        Entry(self, textvariable=self._printer_name).grid(column=1, row=10)

        Label(self).grid(column=1, row=20)

        Button(self, text="Save", command=self._save).grid(column=1,
                                                           row=30,
                                                           sticky=N + S + E)
        Button(self, text=u"Cancel", command=self._back).grid(column=0,
                                                              row=100)

        self.update()

    def _save(self):
        printer_name = self._printer_name.get()
        self._configuration_api.add_printer(printer_name)
        self.navigate(SetupUI)

    def _back(self):
        self.navigate(SetupUI)

    def close(self):
        pass
    def test_sublayer_height_mm_returns_theight(self, mock_load):
        expected = 7.0
        mock_load.return_value =  { 'name':'name', 'sublayer_height_mm': expected }
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        self.assertEquals(expected,configuration_API.get_sublayer_height_mm())
    def test_get_available_audio_options_sets_currently_selected(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [{'sample_rate' : 48000, 'depth': '16 bit' },{'sample_rate' : 44100, 'depth': '16 bit' }], 
            "output": [{'sample_rate' : 48000, 'depth': '16 bit' },{'sample_rate' : 44100, 'depth': '16 bit' }]
            }

        mock_get_valid_sampling_options.return_value = audio_options
        config = self.DEFAULT_CONFIG.copy()
        config['input_bit_depth'] = '16 bit'
        config['input_sample_frequency'] = 44100
        config['output_bit_depth'] = '16 bit'
        config['output_sample_frequency'] = 44100

        mock_load.return_value = config

        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer("Printer")

        actual = capi.get_available_audio_options()

        in1 = AudioSetting(44100,'16 bit', current = True)
        in2 = AudioSetting(48000,'16 bit', recommended = True)
        out1 = AudioSetting(44100,'16 bit', current = True)
        out2 = AudioSetting(48000,'16 bit', recommended = True)
        

        self.assertListContentsEqual([in1, in2],actual['inputs'])
        self.assertListContentsEqual([out1, out2],actual['outputs'])
    def initialize(self):
        self.grid()
        self._current_printer = self.kwargs['printer']
        self._configuration_api = ConfigurationAPI(self._configuration_manager)
        self._configuration_api.load_printer(self._current_printer)

        self._base_height = IntVar()
        self._base_height.set(3)
        self._total_height = IntVar()
        self._total_height.set(23)
        self._start_speed = IntVar()
        self._start_speed.set(50)
        self._stop_speed = IntVar()
        self._stop_speed.set(250)
        self._best_height = IntVar()
        self._best_height.set(0)

        Label(self, text='Printer: ').grid(column=0, row=10)
        Label(self,
              text=self._configuration_api.current_printer()).grid(column=1,
                                                                   row=10)
        Button(self, text='?', command=self._help).grid(column=2,
                                                        row=10,
                                                        stick=N + E)

        Label(self).grid(column=1, row=15)

        Label(self, text="Base Height (mm)").grid(column=0, row=20)
        Entry(self, textvariable=self._base_height).grid(column=1, row=20)

        Label(self, text="Total Height (mm)").grid(column=0, row=30)
        Entry(self, textvariable=self._total_height).grid(column=1, row=30)

        Label(self, text="Start Speed (mm)").grid(column=0, row=40)
        Entry(self, textvariable=self._start_speed).grid(column=1, row=40)

        Label(self, text="Finish Speed (mm)").grid(column=0, row=50)
        Entry(self, textvariable=self._stop_speed).grid(column=1, row=50)
        Label(self).grid(column=1, row=60)

        Button(self, text="Run Test",
               command=self._start).grid(column=2, row=70, sticky=N + S + E)

        Label(self).grid(column=1, row=80)

        Label(self, text="Best height above base (mm)").grid(column=0, row=90)
        self._best_height_field = Entry(self, textvariable=self._best_height)
        self._best_height_field.grid(column=1, row=90)

        Label(self).grid(column=1, row=100)

        Button(self, text="Save", command=self._save).grid(column=2,
                                                           row=110,
                                                           sticky=N + S + W)
        Button(self, text="Back", command=self._back).grid(column=0,
                                                           row=110,
                                                           sticky=N + S + W)

        self.update()
    def test_add_printer_should_save_itself(self, mock_save, mock_new):
        capi = ConfigurationAPI(ConfigurationManager())
        mock_new.return_value = "Some Printer Config"

        capi.add_printer("NewName")

        mock_new.assert_called_with("NewName")
        mock_save.assert_called_with("Some Printer Config")
    def test_add_printer_should_save_itself(self, mock_save, mock_new):
        capi = ConfigurationAPI(ConfigurationManager())
        mock_new.return_value = "Some Printer Config"

        capi.add_printer("NewName")

        mock_new.assert_called_with("NewName")
        mock_save.assert_called_with("Some Printer Config")
    def test_current_printer_returns_printer_name(self, mock_new, mock_save):
        capi = ConfigurationAPI(ConfigurationManager())
        mock_new.return_value = { 'name' : 'Spam' }
        capi.add_printer('Spam')

        actual = capi.current_printer()

        self.assertEqual('Spam', actual)
    def test_get_emulated_drips_per_second_should_return(self, mock_load):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.default_config
        configuration_API.load_printer('Printer')

        actual = configuration_API.get_emulated_drips_per_second()

        self.assertEquals(self.default_config.dripper.emulated_drips_per_second, actual)
    def test_start_counting_drips_should_start_getting_drips(self, mock_start,mock_load,mock_save):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.DEFAULT_CONFIG
        configuration_API.load_printer('printer')

        configuration_API.start_counting_drips()

        mock_start.assert_called_with()
    def test_load_printer_calls_load(self, mock_load):
        printer_name = 'MegaPrint'
        mock_load.return_value = { 'name':printer_name}
        capi = ConfigurationAPI(ConfigurationManager())
        
        capi.load_printer(printer_name)

        mock_load.assert_called_with(printer_name)
    def test_get_dripper_type_should_return_current_type(self, mock_load):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.default_config
        configuration_API.load_printer('Printer')

        actual = configuration_API.get_dripper_type()

        self.assertEquals(self.default_config.dripper.dripper_type, actual)
    def test_load_printer_calls_load(self, mock_load):
        printer_name = 'MegaPrint'
        mock_load.return_value = { 'name':printer_name}
        capi = ConfigurationAPI(ConfigurationManager())
        
        capi.load_printer(printer_name)

        mock_load.assert_called_with(printer_name)
    def test_get_available_printers_lists_printers(self, mock_list):
        printers = ['Tom','Dick','Harry']
        capi = ConfigurationAPI(ConfigurationManager())
        mock_list.return_value = printers

        actual = capi.get_available_printers()

        mock_list.assert_called_with()
        self.assertEqual(printers,actual)
    def test_start_counting_drips_should_use_audio_input_settings(self, mock_load, mock_save, mock_DripBasedZAxis):
        mock_drip_based_zaxis = mock_DripBasedZAxis
        mock_load.return_value =  self.DEFAULT_CONFIG
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer('printer')

        configuration_API.start_counting_drips()

        mock_DripBasedZAxis.assert_called_with(1, sample_rate=48000, bit_depth='16 bit',drip_call_back = None)
    def test_get_drips_per_mm_should_return_current_setting_if_unmarked(self, mock_load):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.DEFAULT_CONFIG

        configuration_API.load_printer('Printer')

        actual = configuration_API.get_drips_per_mm()

        self.assertEquals(self.DEFAULT_CONFIG['drips_per_mm'], actual)
    def test_get_max_lead_distance_mm_returns_max_lead_distance(self, mock_load):
        expected = 0.4
        config = self.DEFAULT_CONFIG.copy()
        config['max_lead_distance_mm'] = expected
        mock_load.return_value =  config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        self.assertEquals(expected,configuration_API.get_max_lead_distance_mm())
    def test_get_max_lead_distance_mm_returns_max_lead_distance(self, mock_load):
        expected = 0.4
        config = self.default_config
        config.dripper.max_lead_distance_mm = expected
        mock_load.return_value =  config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        self.assertEquals(expected,configuration_API.get_max_lead_distance_mm())
    def test_get_drips_per_mm_should_return_current_setting_if_unmarked(self, mock_load):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.default_config

        configuration_API.load_printer('Printer')

        actual = configuration_API.get_drips_per_mm()

        self.assertEquals(self.default_config.dripper.drips_per_mm, actual)
    def test_get_config_returns_current_config(self, mock_load):
        expected = { 'name':'MegaPrint' }
        mock_load.return_value = expected
        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer('printer')

        actual = capi.get_current_config()
        
        self.assertEquals(expected, actual)
    def test_get_config_returns_current_config(self, mock_load):
        expected = { 'name':'MegaPrint' }
        mock_load.return_value = expected
        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer('printer')

        actual = capi.get_current_config()
        
        self.assertEquals(expected, actual)
    def test_get_laser_thickness_mm_returns_thickness(self, mock_load):
        expected = 7.0
        config = self.default_config
        config.options.laser_thickness_mm = expected
        mock_load.return_value =  config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        self.assertEquals(expected,configuration_API.get_laser_thickness_mm())
    def test_get_laser_thickness_mm_returns_thickness(self, mock_load):
        expected = 7.0
        config = self.DEFAULT_CONFIG.copy()
        config['laser_thickness_mm'] = expected
        mock_load.return_value =  config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        self.assertEquals(expected,configuration_API.get_laser_thickness_mm())
    def test_get_available_printers_lists_printers(self, mock_list):
        printers = ['Tom','Dick','Harry']
        capi = ConfigurationAPI(ConfigurationManager())
        mock_list.return_value = printers

        actual = capi.get_available_printers()

        mock_list.assert_called_with()
        self.assertEqual(printers,actual)
    def test_sublayer_height_mm_returns_theight(self, mock_load):
        expected = 7.0
        expected_config = self.default_config
        expected_config.options.sublayer_height_mm = expected
        mock_load.return_value =  expected_config

        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        self.assertEquals(expected,configuration_API.get_sublayer_height_mm())
 def test_set_speed(self, mock_save, mock_load):
     mock_load.return_value = self.default_config
     expected = self.default_config
     expected.options.draw_speed = 121.0
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     configuration_API.set_speed(121)
     
     self.assertConfigurationEqual(expected, mock_save.mock_calls[0][1][0])
 def test_set_speed(self, mock_save, mock_load):
     mock_load.return_value = self.DEFAULT_CONFIG.copy()
     expected_config = self.DEFAULT_CONFIG.copy()
     expected_config['draw_speed'] = 121.0
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     configuration_API.set_speed(121)
     
     mock_save.assert_called_with(expected_config)
    def initialize(self):
        self.grid()

        self._current_printer = self.kwargs['printer']
        self._configuration_api = ConfigurationAPI(self._configuration_manager)

        Label(self, text=self._current_printer).grid(column=1, row=10)
        Button(self, text="Do not delete", command=self._back).grid(column=1,
                                                                    row=110)
        Button(self, text="Yes, delete",
               command=self._remove_printer).grid(column=1, row=120)
    def test_current_printer_returns_printer_name(self, mock_new, mock_save):
        capi = ConfigurationAPI(ConfigurationManager())
        name = "Spam"
        config = self.default_config
        config.name = name
        mock_new.return_value = config
        capi.add_printer('Spam')

        actual = capi.current_printer()

        self.assertEqual('Spam', actual)
    def test_set_audio_input_options_should_update_when_48000(self, mock_save, mock_load):
        config =  self.default_config
        mock_load.return_value = config
        capi = ConfigurationAPI(ConfigurationManager())
        expected = self.default_config
        expected.audio.input.bit_depth = '32 bit Floating Point'
        expected.audio.input.sample_rate =  48000

        capi.load_printer('Printer')
        
        actual = capi.set_audio_input_options(AudioSetting(48000,'32 bit Floating Point'))

        self.assertConfigurationEqual(expected, mock_save.mock_calls[0][1][0])
    def test_set_audio_input_options_should_update_when_48000(self, mock_save, mock_load):
        config =  self.DEFAULT_CONFIG.copy()
        mock_load.return_value = config
        capi = ConfigurationAPI(ConfigurationManager())
        expected = config.copy()
        expected['input_bit_depth'] = '32 bit Floating Point'
        expected['input_sample_frequency'] =  48000

        capi.load_printer('Printer')
        
        actual = capi.set_audio_input_options(AudioSetting(48000,'32 bit Floating Point'))

        mock_save.assert_called_with(expected)
    def test_set_audio_output_options_should_update_output_when_44100(self, mock_save, mock_load):
        mock_load.return_value = self.default_config
        capi = ConfigurationAPI(ConfigurationManager())
        expected = self.default_config
        expected.audio.output.modulation_on_frequency = 11025
        expected.audio.output.modulation_off_frequency = 2205
        expected.audio.output.bit_depth = '16 bit'
        expected.audio.output.sample_rate =  44100

        capi.load_printer("Printer")
        
        actual = capi.set_audio_output_options(AudioSetting(44100, '16 bit'))
        self.assertConfigurationEqual(expected, mock_save.mock_calls[0][1][0])
    def test_set_audio_output_options_should_update_output_when_44100(self, mock_save, mock_load):
        config = self.DEFAULT_CONFIG.copy()
        mock_load.return_value = config
        capi = ConfigurationAPI(ConfigurationManager())
        expected = config.copy()
        expected['on_modulation_frequency'] = 11025
        expected['off_modulation_frequency'] = 3675
        expected['output_bit_depth'] = '16 bit'
        expected['output_sample_frequency'] =  44100

        capi.load_printer("Printer")
        
        actual = capi.set_audio_output_options(AudioSetting(44100, '16 bit'))

        mock_save.assert_called_with(expected)
    def test_mark_drips_should_when_target_specified(self, mock_current_z_location_mm, mock_start,mock_load,mock_save):
        fake_drip_counter = 70
        target_height = 10.0
        expected_drips_per_mm = fake_drip_counter / target_height
        
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.DEFAULT_CONFIG.copy()
        configuration_API.load_printer('printer')
        mock_current_z_location_mm.return_value = fake_drip_counter
        
        configuration_API.start_counting_drips()
        configuration_API.set_target_height(target_height)
        configuration_API.mark_drips_at_target()

        self.assertEquals(expected_drips_per_mm, configuration_API.get_drips_per_mm())
        self.assertFalse(mock_save.called)
    def initialize(self):
        self.grid()
        self.file_opt = options = {}
        options['defaultextension'] = '.gcode'
        options['filetypes'] = [('GCode files', '.gcode'),('all files', '.*'), ]
        options['initialdir'] = '.'
        options['parent'] = self
        options['title'] = 'Select file to print'

        self._configuration_api = ConfigurationAPI(self._configuration_manager)
        self._printer_selection_current = StringVar()
        if not self._configuration_api.get_available_printers():
            self._configuration_api.add_printer("Peachy Printer")
        available_printers = self._configuration_api.get_available_printers() 

        self._printer_selection_current.set(available_printers[0])
        self._printer_selected(available_printers[0])

        OptionMenu(self, self._printer_selection_current, *available_printers, command = self._printer_selected).grid(column=1,row=10,sticky=N+S+E+W)
        Label(self).grid(column=1,row=20)
        Button(self,text=u"Verify G Code", command=self.verify_g_code_click).grid(column=1,row=25,sticky=N+S+E+W)
        Button(self,text=u"Print G Code", command=self.print_g_code_click).grid(column=1,row=30,sticky=N+S+E+W)
        Label(self).grid(column=1,row=40)
        Button(self,text=u"Back", command=self._back).grid(column=0,row=50)

        self.update()
    def test_set_audio_output_options_should_update_output_when_48000(self, mock_save, mock_load):
        printer_name = 'MegaPrint'
        config =  self.default_config
        mock_load.return_value = config
        capi = ConfigurationAPI(ConfigurationManager())
        expected = self.default_config
        expected.audio.output.modulation_on_frequency = 12000
        expected.audio.output.modulation_off_frequency = 2000
        expected.audio.output.bit_depth = '32 bit Floating Point'
        expected.audio.output.sample_rate =  48000

        capi.load_printer(printer_name)
        
        actual = capi.set_audio_output_options(AudioSetting(48000,'32 bit Floating Point'))

        self.assertConfigurationEqual(expected, mock_save.mock_calls[0][1][0])
    def test_get_speed_at_height_must_have_height_between_total_and_base(self, mock_load):
        mock_load.return_value = self.default_config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_speed_at_height(0,10,1,2,11)
        with self.assertRaises(Exception):
            configuration_API.get_speed_at_height(2,10,1,2,0)
    def test_stop_counting_drips_should_stop_getting_drips(self, mock_stop,mock_start,mock_load,mock_save):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.default_config
        configuration_API.load_printer('printer')
        configuration_API.start_counting_drips()

        configuration_API.stop_counting_drips()

        mock_stop.assert_called_with()
    def test_drip_calibration_should_call_reset_when_reset_requested(self, mock_reset,mock_start,mock_load,mock_save):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.default_config
        configuration_API.load_printer('printer')

        configuration_API.start_counting_drips()
        configuration_API.reset_drips()

        mock_reset.assert_called_with(0)
    def test_get_speed_at_height_must_exceed_base_height(self, mock_load):
        mock_load.return_value = self.default_config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_speed_at_height(10,1,1,2,1)
        with self.assertRaises(Exception):
            configuration_API.get_speed_at_height(1,1,1,2,1)
    def test_get_cure_test_final_speed_exceeds_start_speed(self, mock_load):
        mock_load.return_value = self.default_config
        configuration_API = ConfigurationAPI(ConfigurationManager())
        configuration_API.load_printer("test")

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,10,1)

        with self.assertRaises(Exception):
            configuration_API.get_cure_test(1,10,1,1)
 def test_set_speed_should_throw_exception_if_less_then_or_0(self, mock_save, mock_load):
     mock_load.return_value = self.default_config
     expected_config = self.default_config
     expected_config.options.draw_speed = 121.0
     configuration_API = ConfigurationAPI(ConfigurationManager())
     configuration_API.load_printer("test")
     
     with self.assertRaises(Exception):
         configuration_API.set_speed(-1)
     with self.assertRaises(Exception):
         configuration_API.set_speed(0)
    def initialize(self):
        self.grid()
        self._configuration_api = ConfigurationAPI(self._configuration_manager)

        self._printer_name = StringVar()

        Label(self, text="Enter a name for your printer").grid(column=0,
                                                               row=10)
        Entry(self, textvariable=self._printer_name).grid(column=1, row=10)

        Label(self).grid(column=1, row=20)

        Button(self, text="Save", command=self._save).grid(column=1,
                                                           row=30,
                                                           sticky=N + S + E)
        Button(self, text=u"Cancel", command=self._back).grid(column=0,
                                                              row=100)

        self.update()
    def test_get_available_audio_options_should_get_list_of_settings(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [{'sample_rate' : 22000, 'depth': '16 bit' }], 
            "output": [{'sample_rate' : 22000, 'depth': '32 bit Floating Point' }]
            }
        expected = {
                    "inputs" : [AudioSetting(22000,'16 bit')],
                    "outputs": [AudioSetting(22000,'32 bit Floating Point')]
                   }

        mock_get_valid_sampling_options.return_value = audio_options
        mock_load.return_value = self.default_config
        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer("Printer")
        
        actual = capi.get_available_audio_options()

        self.assertListContentsEqual(expected['inputs'],actual['inputs'])
        self.assertListContentsEqual(expected['outputs'],actual['outputs'])
    def test_set_dripper_type_should_return_current_type(self, mock_load):
        configuration_API = ConfigurationAPI(ConfigurationManager())
        mock_load.return_value = self.default_config
        configuration_API.load_printer('Printer')
        expected = 'emulated'
        configuration_API.set_dripper_type(expected)
        actual = configuration_API.get_dripper_type()

        self.assertEquals(expected, actual)