Exemple #1
0
    def test_file_mimetype_specified_once_only(self):
        with temp_file_contents(b"Hi") as f:
            self.patch(_output, '_CHUNK_SIZE', 1)
            result = get_result_for([
                self.option,
                self.test_id,
                '--attach-file',
                f.name,
                '--mimetype',
                'text/plain',
            ])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(test_id=self.test_id,
                                      mime_type='text/plain',
                                      file_bytes=b'H',
                                      eof=False),
                    MatchesStatusCall(test_id=self.test_id,
                                      mime_type=None,
                                      file_bytes=b'i',
                                      eof=True),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #2
0
    def test_test_status_specified_once_only(self):
        with temp_file_contents(b"Hi") as f:
            self.patch(_output, '_CHUNK_SIZE', 1)
            result = get_result_for([
                self.option,
                self.test_id,
                '--attach-file',
                f.name,
            ])

            # 'inprogress' status should be on the first packet only, all other
            # statuses should be on the last packet.
            if self.status in _output._FINAL_ACTIONS:
                first_call = MatchesStatusCall(test_id=self.test_id,
                                               test_status=None)
                last_call = MatchesStatusCall(test_id=self.test_id,
                                              test_status=self.status)
            else:
                first_call = MatchesStatusCall(test_id=self.test_id,
                                               test_status=self.status)
                last_call = MatchesStatusCall(test_id=self.test_id,
                                              test_status=None)
            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    first_call,
                    last_call,
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #3
0
    def test_file_chunk_size_is_honored(self):
        with temp_file_contents(b"Hello") as f:
            self.patch(_output, '_CHUNK_SIZE', 1)
            result = get_result_for(
                [self.option, self.test_id, '--attach-file', f.name])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(test_id=self.test_id,
                                      file_bytes=b'H',
                                      eof=False),
                    MatchesStatusCall(test_id=self.test_id,
                                      file_bytes=b'e',
                                      eof=False),
                    MatchesStatusCall(test_id=self.test_id,
                                      file_bytes=b'l',
                                      eof=False),
                    MatchesStatusCall(test_id=self.test_id,
                                      file_bytes=b'l',
                                      eof=False),
                    MatchesStatusCall(test_id=self.test_id,
                                      file_bytes=b'o',
                                      eof=True),
                    MatchesStatusCall(call='stopTestRun')
                ]))
Exemple #4
0
 def match(self, matchee):
     checks = []
     checks.append(matchers.IsInstance(MultiCheck))
     checks.append(
         matchers.AfterPreprocessing(operator.attrgetter('strategy'),
                                     matchers.Is(self.strategy)))
     checks.append(
         matchers.AfterPreprocessing(
             operator.attrgetter('subchecks'),
             matchers.MatchesListwise(self.subchecks)))
     return matchers.MatchesAll(*checks).match(matchee)
Exemple #5
0
    def test_file_is_sent_in_single_packet(self):
        with temp_file_contents(b"Hello") as f:
            result = get_result_for(
                [self.option, self.test_id, '--attach-file', f.name])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(file_bytes=b'Hello', eof=True),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #6
0
    def test_can_specify_tags_without_test_status(self):
        result = get_result_for([
            '--tag',
            'foo',
        ])

        self.assertThat(
            result._events,
            matchers.MatchesListwise([
                MatchesStatusCall(call='startTestRun'),
                MatchesStatusCall(test_tags=set(['foo'])),
                MatchesStatusCall(call='stopTestRun'),
            ]))
Exemple #7
0
    def test_file_name_is_used_by_default(self):
        with temp_file_contents(b"Hello") as f:
            result = get_result_for(['--attach-file', f.name])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(file_name=f.name,
                                      file_bytes=b'Hello',
                                      eof=True),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #8
0
    def test_can_attach_file_without_test_id(self):
        with temp_file_contents(b"Hello") as f:
            result = get_result_for(['--attach-file', f.name])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(test_id=None,
                                      file_bytes=b'Hello',
                                      eof=True),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #9
0
    def test_can_read_binary_files(self):
        with temp_file_contents(b"\xDE\xAD\xBE\xEF") as f:
            result = get_result_for(
                [self.option, self.test_id, '--attach-file', f.name])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(file_bytes=b"\xDE\xAD\xBE\xEF",
                                      eof=True),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #10
0
    def test_filename_can_be_overridden(self):
        with temp_file_contents(b"Hello") as f:
            specified_file_name = self.getUniqueString()
            result = get_result_for(
                ['--attach-file', f.name, '--file-name', specified_file_name])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(file_name=specified_file_name,
                                      file_bytes=b'Hello'),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #11
0
    def test_can_read_stdin(self):
        self.patch(_output.sys, 'stdin',
                   io.TextIOWrapper(io.BytesIO(b"\xFE\xED\xFA\xCE")))
        result = get_result_for(
            [self.option, self.test_id, '--attach-file', '-'])

        self.assertThat(
            result._events,
            matchers.MatchesListwise([
                MatchesStatusCall(call='startTestRun'),
                MatchesStatusCall(file_bytes=b"\xFE\xED\xFA\xCE",
                                  file_name='stdin',
                                  eof=True),
                MatchesStatusCall(call='stopTestRun'),
            ]))
Exemple #12
0
    def test_files_have_timestamp(self):
        _dummy_timestamp = datetime.datetime(2013, 1, 1, 0, 0, 0, 0,
                                             iso8601.UTC)
        self.patch(_output, 'create_timestamp', lambda: _dummy_timestamp)

        with temp_file_contents(b"Hello") as f:
            result = get_result_for([
                '--attach-file',
                f.name,
            ])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(file_bytes=b'Hello',
                                      timestamp=_dummy_timestamp),
                    MatchesStatusCall(call='stopTestRun'),
                ]))
Exemple #13
0
    def test_timestamp_specified_once_only(self):
        with temp_file_contents(b"Hi") as f:
            self.patch(_output, '_CHUNK_SIZE', 1)
            result = get_result_for([
                self.option,
                self.test_id,
                '--attach-file',
                f.name,
            ])

            self.assertThat(
                result._events,
                matchers.MatchesListwise([
                    MatchesStatusCall(call='startTestRun'),
                    MatchesStatusCall(test_id=self.test_id,
                                      timestamp=self._dummy_timestamp),
                    MatchesStatusCall(test_id=self.test_id, timestamp=None),
                    MatchesStatusCall(call='stopTestRun'),
                ]))