Ejemplo n.º 1
0
    def setUp(self):
        super(CandidatesWorkUnitTest, self).setUp()

        self.workunit = CandidatesWorkUnit(self.testfile, self.data,
                                           self.progress_manager,
                                           self.output_context)
        self.writer = Mock(spec=StreamingAstromWriter)
        self.workunit.get_writer = Mock(return_value=self.writer)
Ejemplo n.º 2
0
 def use_cands_workunit(self):
     self.workunit = CandidatesWorkUnit("file", self.data,
                                        self.progress_manager,
                                        self.output_context)
     self.workunit.get_writer = Mock()
     self.model.add_workunit(self.workunit)
     assert_that(self.model.get_current_reading(),
                 equal_to(self.sources[0].get_reading(0)))
Ejemplo n.º 3
0
    def setUp(self):
        super(CandidatesWorkUnitTest, self).setUp()

        self.workunit = CandidatesWorkUnit(self.testfile, self.data,
                                           self.progress_manager,
                                           self.output_context)
        self.writer = Mock(spec=StreamingAstromWriter)
        self.workunit.get_writer = Mock(return_value=self.writer)
Ejemplo n.º 4
0
class CandidatesWorkUnitTest(AbstractWorkUnitTest):
    def get_input_file(self):
        return "data/1584431p15.measure3.cands.astrom"

    def setUp(self):
        super(CandidatesWorkUnitTest, self).setUp()

        self.workunit = CandidatesWorkUnit(self.testfile, self.data,
                                           self.progress_manager,
                                           self.output_context)
        self.writer = Mock(spec=StreamingAstromWriter)
        self.workunit.get_writer = Mock(return_value=self.writer)

    def test_output_filename(self):
        assert_that(self.workunit.get_output_filename(),
                    equal_to(self.testfile.replace(".cands", ".reals")))

    def test_next_vettable_item(self):
        assert_that(self.workunit.get_current_source_number(), equal_to(0))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

        self.workunit.next_item()
        assert_that(self.workunit.get_current_source_number(), equal_to(1))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

        self.workunit.next_item()
        assert_that(self.workunit.get_current_source_number(), equal_to(2))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

        self.workunit.next_item()
        assert_that(self.workunit.get_current_source_number(), equal_to(0))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

    def test_accept_current_item(self):
        first_item = self.data.get_sources()[0]
        second_item = self.data.get_sources()[1]

        assert_that(self.workunit.is_item_processed(first_item),
                    equal_to(False))
        assert_that(self.workunit.is_item_processed(second_item),
                    equal_to(False))

        self.workunit.accept_current_item()

        assert_that(self.workunit.is_item_processed(first_item),
                    equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item),
                    equal_to(False))

        self.workunit.next_item()
        self.workunit.accept_current_item()

        assert_that(self.workunit.is_item_processed(first_item),
                    equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item),
                    equal_to(True))

    def test_reject_current_item(self):
        first_item = self.data.get_sources()[0]
        second_item = self.data.get_sources()[1]

        assert_that(self.workunit.is_item_processed(first_item),
                    equal_to(False))
        assert_that(self.workunit.is_item_processed(second_item),
                    equal_to(False))

        self.workunit.reject_current_item()

        assert_that(self.workunit.is_item_processed(first_item),
                    equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item),
                    equal_to(False))

        self.workunit.next_item()
        self.workunit.reject_current_item()

        assert_that(self.workunit.is_item_processed(first_item),
                    equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item),
                    equal_to(True))

    def test_get_unprocessed_sources(self):
        sources = self.data.get_sources()

        assert_that(self.workunit.get_unprocessed_sources(),
                    contains_inanyorder(*sources))

        self.workunit.accept_current_item()

        assert_that(self.workunit.get_unprocessed_sources(),
                    contains_inanyorder(sources[1], sources[2]))

        self.workunit.next_item()
        self.workunit.reject_current_item()

        assert_that(self.workunit.get_unprocessed_sources(),
                    contains_inanyorder(sources[2]))

        self.workunit.next_item()
        self.workunit.accept_current_item()

        assert_that(self.workunit.get_unprocessed_sources(), has_length(0))

    def test_finish_workunit_unlocks_file(self):
        self.workunit.accept_current_item()
        self.workunit.next_item()
        self.workunit.accept_current_item()
        self.workunit.next_item()
        self.workunit.accept_current_item()

        self.progress_manager.unlock.assert_called_once_with(self.testfile,
                                                             do_async=True)
Ejemplo n.º 5
0
class CandidatesWorkUnitTest(AbstractWorkUnitTest):
    def get_input_file(self):
        return "data/1584431p15.measure3.cands.astrom"

    def setUp(self):
        super(CandidatesWorkUnitTest, self).setUp()

        self.workunit = CandidatesWorkUnit(self.testfile, self.data,
                                           self.progress_manager,
                                           self.output_context)
        self.writer = Mock(spec=StreamingAstromWriter)
        self.workunit.get_writer = Mock(return_value=self.writer)

    def test_output_filename(self):
        assert_that(self.workunit.get_output_filename(),
                    equal_to(self.testfile.replace(".cands", ".reals")))

    def test_next_vettable_item(self):
        assert_that(self.workunit.get_current_source_number(), equal_to(0))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

        self.workunit.next_item()
        assert_that(self.workunit.get_current_source_number(), equal_to(1))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

        self.workunit.next_item()
        assert_that(self.workunit.get_current_source_number(), equal_to(2))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

        self.workunit.next_item()
        assert_that(self.workunit.get_current_source_number(), equal_to(0))
        assert_that(self.workunit.get_current_obs_number(), equal_to(0))

    def test_accept_current_item(self):
        first_item = self.data.get_sources()[0]
        second_item = self.data.get_sources()[1]

        assert_that(self.workunit.is_item_processed(first_item), equal_to(False))
        assert_that(self.workunit.is_item_processed(second_item), equal_to(False))

        self.workunit.accept_current_item()

        assert_that(self.workunit.is_item_processed(first_item), equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item), equal_to(False))

        self.workunit.next_item()
        self.workunit.accept_current_item()

        assert_that(self.workunit.is_item_processed(first_item), equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item), equal_to(True))

    def test_reject_current_item(self):
        first_item = self.data.get_sources()[0]
        second_item = self.data.get_sources()[1]

        assert_that(self.workunit.is_item_processed(first_item), equal_to(False))
        assert_that(self.workunit.is_item_processed(second_item), equal_to(False))

        self.workunit.reject_current_item()

        assert_that(self.workunit.is_item_processed(first_item), equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item), equal_to(False))

        self.workunit.next_item()
        self.workunit.reject_current_item()

        assert_that(self.workunit.is_item_processed(first_item), equal_to(True))
        assert_that(self.workunit.is_item_processed(second_item), equal_to(True))

    def test_get_unprocessed_sources(self):
        sources = self.data.get_sources()

        assert_that(self.workunit.get_unprocessed_sources(),
                    contains_inanyorder(*sources))

        self.workunit.accept_current_item()

        assert_that(self.workunit.get_unprocessed_sources(),
                    contains_inanyorder(sources[1], sources[2]))

        self.workunit.next_item()
        self.workunit.reject_current_item()

        assert_that(self.workunit.get_unprocessed_sources(),
                    contains_inanyorder(sources[2]))

        self.workunit.next_item()
        self.workunit.accept_current_item()

        assert_that(self.workunit.get_unprocessed_sources(),
                    has_length(0))

    def test_finish_workunit_unlocks_file(self):
        self.workunit.accept_current_item()
        self.workunit.next_item()
        self.workunit.accept_current_item()
        self.workunit.next_item()
        self.workunit.accept_current_item()

        self.progress_manager.unlock.assert_called_once_with(
            self.testfile, async=True)