コード例 #1
0
ファイル: test_lco.py プロジェクト: fraserw/tom_base
    def test_build_guiding_config(self, mock_validate, mock_insts,
                                  mock_filters, mock_proposals):
        mock_validate.return_value = []
        mock_insts.return_value = self.instrument_choices
        mock_filters.return_value = self.filter_choices
        mock_proposals.return_value = self.proposal_choices

        test_params = [({
            'guider_mode': 'on'
        }, {
            'mode': 'ON',
            'optional': 'false'
        }), ({
            'guider_mode': 'off'
        }, {
            'mode': 'OFF',
            'optional': 'false'
        }), ({
            'guider_mode': 'optional'
        }, {
            'mode': 'ON',
            'optional': 'true'
        })]
        for params in test_params:
            with self.subTest():
                self.valid_form_data.update(params[0])
                form = LCOSpectroscopicSequenceForm(self.valid_form_data)
                self.assertTrue(form.is_valid())
                guiding_config = form._build_guiding_config()
                self.assertDictEqual(params[1], guiding_config)
コード例 #2
0
ファイル: test_lco.py プロジェクト: fraserw/tom_base
    def test_build_location(self, mock_get_instruments, mock_validate,
                            mock_insts, mock_filters, mock_proposals):
        mock_get_instruments.return_value = {
            k: v
            for k, v in instrument_response.items() if 'SOAR' not in k
        }
        mock_validate.return_value = []
        mock_insts.return_value = self.instrument_choices
        mock_filters.return_value = self.filter_choices
        mock_proposals.return_value = self.proposal_choices

        test_params = [({
            'site': 'ogg'
        }, {
            'site': 'ogg'
        }), ({
            'site': 'coj'
        }, {
            'site': 'coj'
        }), ({
            'site': 'any'
        }, {})]
        for params in test_params:
            with self.subTest():
                self.valid_form_data.update(params[0])
                form = LCOSpectroscopicSequenceForm(self.valid_form_data)
                self.assertTrue(form.is_valid())
                location = form._build_location()
                self.assertDictContainsSubset(params[1], location)
コード例 #3
0
ファイル: test_lco.py プロジェクト: JulienPeloton/tom_base
    def test_build_instrument_config(self, mock_validate, mock_insts, mock_filters, mock_proposals):
        mock_validate.return_value = []
        mock_insts.return_value = self.instrument_choices
        mock_filters.return_value = self.filter_choices
        mock_proposals.return_value = self.proposal_choices

        form = LCOSpectroscopicSequenceForm(self.valid_form_data)
        self.assertTrue(form.is_valid())
        inst_config = form._build_instrument_config()
        self.assertEqual(len(inst_config), 1)
        self.assertIn({'exposure_count': 1, 'exposure_time': 30.0, 'optical_elements': {'slit': 'slit_1.2as'}},
                      inst_config)
        self.assertNotIn('filter', inst_config[0]['optical_elements'])
コード例 #4
0
ファイル: test_lco.py プロジェクト: fraserw/tom_base
    def test_build_acquisition_config(self, mock_validate, mock_insts,
                                      mock_filters, mock_proposals):
        mock_validate.return_value = []
        mock_insts.return_value = self.instrument_choices
        mock_filters.return_value = self.filter_choices
        mock_proposals.return_value = self.proposal_choices

        with self.subTest():
            form = LCOSpectroscopicSequenceForm(self.valid_form_data)
            self.assertTrue(form.is_valid())
            acquisition_config = form._build_acquisition_config()
            self.assertDictEqual(
                {
                    'mode': 'BRIGHTEST',
                    'extra_params': {
                        'acquire_radius': 1
                    }
                }, acquisition_config)

        with self.subTest():
            self.valid_form_data.pop('acquisition_radius')
            form = LCOSpectroscopicSequenceForm(self.valid_form_data)
            self.assertTrue(form.is_valid())
            acquisition_config = form._build_acquisition_config()
            self.assertDictEqual({'mode': 'WCS'}, acquisition_config)
コード例 #5
0
ファイル: test_lco.py プロジェクト: JulienPeloton/tom_base
    def test_instrument_choices(self, mock_get_instruments):
        """Test LCOSpectroscopicSequenceForm._instrument_choices."""
        mock_get_instruments.return_value = generate_lco_instrument_choices()

        inst_choices = LCOSpectroscopicSequenceForm.instrument_choices()
        self.assertIn(('2M0-FLOYDS-SCICAM', '2.0 meter FLOYDS'), inst_choices)
        self.assertNotIn(('0M4-SCICAM-SBIG', '0.4 meter SBIG'), inst_choices)
        self.assertEqual(len(inst_choices), 1)
コード例 #6
0
ファイル: test_lco.py プロジェクト: fraserw/tom_base
    def test_instrument_choices(self, mock_get_instruments):
        """Test LCOSpectroscopicSequenceForm._instrument_choices."""
        mock_get_instruments.return_value = {
            k: v
            for k, v in instrument_response.items() if 'SOAR' not in k
        }

        inst_choices = LCOSpectroscopicSequenceForm.instrument_choices()
        self.assertIn(('2M0-FLOYDS-SCICAM', '2.0 meter FLOYDS'), inst_choices)
        self.assertNotIn(('0M4-SCICAM-SBIG', '0.4 meter SBIG'), inst_choices)
        self.assertEqual(len(inst_choices), 1)
コード例 #7
0
ファイル: test_lco.py プロジェクト: JulienPeloton/tom_base
    def test_filter_choices(self, mock_get_instruments):
        """Test LCOSpectroscopicSequenceForm._instrument_choices."""
        mock_get_instruments.return_value = generate_lco_instrument_choices()

        filter_choices = LCOSpectroscopicSequenceForm.filter_choices()
        for expected in [('slit_6.0as', '6.0 arcsec slit'), ('slit_1.6as', '1.6 arcsec slit'),
                         ('slit_2.0as', '2.0 arcsec slit'), ('slit_1.2as', '1.2 arcsec slit')]:
            self.assertIn(expected, filter_choices)
        for not_expected in [('opaque', 'Opaque'), ('100um-Pinhole', '100um Pinhole')]:
            self.assertNotIn(not_expected, filter_choices)
        self.assertEqual(len(filter_choices), 4)
コード例 #8
0
ファイル: test_lco.py プロジェクト: fraserw/tom_base
    def test_clean(self, mock_validate, mock_insts, mock_filters,
                   mock_proposals):
        mock_validate.return_value = []
        mock_insts.return_value = self.instrument_choices
        mock_filters.return_value = self.filter_choices
        mock_proposals.return_value = self.proposal_choices

        # Test that a valid form returns True, and that start and end are cleaned properly
        form = LCOSpectroscopicSequenceForm(self.valid_form_data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data['instrument_type'],
                         '2M0-FLOYDS-SCICAM')
        self.assertAlmostEqual(
            datetime.strftime(datetime.now(), '%Y-%m-%dT%H:%M:%S'),
            form.cleaned_data['start'])
        self.assertAlmostEqual(
            datetime.strftime(
                datetime.now() +
                timedelta(hours=form.cleaned_data['cadence_frequency']),
                '%Y-%m-%dT%H:%M:%S'), form.cleaned_data['end'])

        # Test that an invalid form returns False
        self.valid_form_data.pop('target_id')
        form = LCOSpectroscopicSequenceForm(self.valid_form_data)
        self.assertFalse(form.is_valid())