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'])
    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_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_get_available_audio_options_is_sorted(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [], 
            "output": [{'sample_rate' : 48000, 'depth': '32 bit Floating Point' },{'sample_rate' : 44100, 'depth': '16 bit' },{'sample_rate' : 48000, 'depth': '16 bit' },{'sample_rate' : 44100, 'depth': '24 bit' } ]
            }

        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()

        expected_ordered = [
            AudioSetting(44100, '16 bit'),
            AudioSetting(44100, '24 bit'),
            AudioSetting(48000, '16 bit', recommended = True, current = True),
            AudioSetting(48000, '32 bit Floating Point'),
        ] 
        self.assertListContentsEqual(expected_ordered,actual['outputs'])
    def test_get_available_audio_options_should_add_recommend_flag_to_one_option(self, mock_load, mock_get_valid_sampling_options):
        audio_options = { 
            "input" : [{'sample_rate' : 48000, 'depth': '32 bit Floating Point' },{'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
        mock_load.return_value = self.default_config
        capi = ConfigurationAPI(ConfigurationManager())
        capi.load_printer("Printer")

        actual = capi.get_available_audio_options()

        expected_input = AudioSetting(44100,'16 bit', recommended = True)
        unexpected_input = AudioSetting(48000,'32 bit Floating Point')
        expected_output = AudioSetting(48000,'16 bit', recommended = True, current = True)
        unexpected_output = AudioSetting(44100,'16 bit')

        self.assertListContentsEqual([expected_input, unexpected_input],actual['inputs'])
        self.assertListContentsEqual([unexpected_output,expected_output],actual['outputs'])
    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_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_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_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_set_current_set_current_flag(self):
     s = AudioSetting(48000,"16 bit")
     s.set_current()
     self.assertTrue(s.current)
 def test_str_returns_human_readable_option_with_recommend_with_recommended(self):
     s = AudioSetting(48000,"16 bit")
     s.set_recommended()
     self.assertEquals("48000 Hz, 16 bit (Recommended)", str(s))
 def test_to_instances_with_diffrent_settings_are_equal(self):
     a = AudioSetting(48000,'16 bit')
     b = AudioSetting(44100,'16 bit')
     self.assertNotEquals(a,b)
 def test_to_instances_with_same_settings_are_equal(self):
     a = AudioSetting(48000,'16 bit')
     b = AudioSetting(48000,'16 bit')
     self.assertEquals(a,b)
 def test_set_current_set_current_flag(self):
     s = AudioSetting(48000,"16 bit")
     s.set_current()
     self.assertTrue(s.current)
 def test_str_returns_human_readable_option_with_recommend_with_recommended(self):
     s = AudioSetting(48000,"16 bit")
     s.set_recommended()
     self.assertEquals("48000 Hz, 16 bit (Recommended)", str(s))
 def test_str_returns_human_readable_option(self):
     s = AudioSetting(48000,"16 bit")
     self.assertEquals("48000 Hz, 16 bit", str(s))