def test_one_property(self): stream = MessagesTest.StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: datetime.min) messages.message("dummyMessage", fruit="apple") self.assertEqual( stream.observed_output, "\n##teamcity[dummyMessage timestamp='0001-01-01T00:00' fruit='apple']\n" )
def main(): parser = argparse.ArgumentParser(description='run_memory_map') parser.add_argument('--toolchain', type=str, help='GCC toolchain path', default='') parser.add_argument('--binutils_prefix', type=str, help='GNU binutils prefix', default='') parser.add_argument('--file', type=str, help='Binary file') parser.add_argument('--key_name', type=str, help='TeamCity buildStatisticValue key name suffix', default='none') args = parser.parse_args() tsm = TeamcityServiceMessages() sections = parse_size(args.toolchain, args.binutils_prefix, args.file) if sections: flash_size = 0 ram_size = 0 other_size = 0 for section in sections: if section.name in ['.text', '.ARM.exidx', '.relocate']: flash_size += section.size elif section.name in ['.bss', '.stack']: ram_size += section.size else: other_size += section.size tsm.message('buildStatisticValue', key='FLASH ({0})'.format(args.key_name), value=str(flash_size)) tsm.message('buildStatisticValue', key='RAM ({0})'.format(args.key_name), value=str(ram_size)) # tsm.message('buildStatisticValue', key='OTHER ({0})'.format(args.key_name), value=str(other_size)) else: tsm.buildProblem('Unable to detect sections', '')
def test_three_properties(self): stream = MessagesTest.StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: datetime.min) messages.message("dummyMessage", fruit="apple", meat="steak", pie="raspberry") self.assertEqual( stream.observed_output, "\n##teamcity[dummyMessage timestamp='0001-01-01T00:00' " "fruit='apple' meat='steak' pie='raspberry']\n", )
def test_three_properties(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) messages.message('dummyMessage', fruit='apple', meat='steak', pie='raspberry') assert stream.observed_output == "\n##teamcity[dummyMessage timestamp='2000-11-02T10:23:01.556' fruit='apple' meat='steak' pie='raspberry']\n"
def test_unicode(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) if sys.version_info < (3, ): bjork = 'Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir'.decode('utf-8') else: bjork = b('Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir').decode('utf-8') messages.message(bjork) assert stream.observed_output == ("\n##teamcity[%s timestamp='2000-11-02T10:23:01.556']\n" % bjork).encode('utf-8')
def test_unicode(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) if sys.version_info < (3, ): bjork = 'Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir'.decode('utf-8') else: bjork = b('Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir').decode('utf-8') messages.message(bjork) assert stream.observed_output == ( "##teamcity[%s timestamp='2000-11-02T10:23:01.556']\n" % bjork).encode('utf-8')
def test_blocks_with_flowid(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) with messages.block("Doing something that's important", flowId='a'): messages.message("Doing stuff") expected_output = textwrap.dedent("""\ ##teamcity[blockOpened timestamp='2000-11-02T10:23:01.556' flowId='a' name='Doing something that|'s important'] ##teamcity[Doing stuff timestamp='2000-11-02T10:23:01.556'] ##teamcity[blockClosed timestamp='2000-11-02T10:23:01.556' flowId='a' name='Doing something that|'s important'] """) expected_output = expected_output.encode('utf-8') assert stream.observed_output == expected_output
def test_message_unicode(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) if sys.version_info < (3, ): bjork = 'Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir'.decode('utf-8') else: bjork = b('Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir').decode('utf-8') messages.message('foo', u=bjork, b=bjork.encode('utf-8')) expected_output = b("##teamcity[foo timestamp='2000-11-02T10:23:01.556' " "b='Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir' " "u='Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir']") assert stream.observed_output.strip() == expected_output
def test_blocks_with_flowid(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) with messages.block("Doing something that's important", flowId='a'): messages.message("Doing stuff") expected_output = textwrap.dedent("""\ ##teamcity[blockOpened timestamp='2000-11-02T10:23:01.556' flowId='a' name='Doing something that|'s important'] ##teamcity[Doing stuff timestamp='2000-11-02T10:23:01.556'] ##teamcity[blockClosed timestamp='2000-11-02T10:23:01.556' flowId='a' name='Doing something that|'s important'] """) expected_output = expected_output.encode('utf-8') assert stream.observed_output == expected_output
def test_mismatched_encoding(encoding, is_message_encodable): stream = CustomEncodingStream(encoding) messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) value = unicodedata.lookup('CYRILLIC CAPITAL LETTER IO') messages.message(value) if is_message_encodable: expected_value = value else: expected_value = value.encode('unicode-escape').decode('latin-1') assert stream.getvalue( ) == "##teamcity[%s timestamp='2000-11-02T10:23:01.556']\n" % expected_value
def test_message_unicode(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) if sys.version_info < (3, ): bjork = 'Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir'.decode('utf-8') else: bjork = b('Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir').decode('utf-8') messages.message('foo', u=bjork, b=bjork.encode('utf-8')) expected_output = b( "##teamcity[foo timestamp='2000-11-02T10:23:01.556' " "b='Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir' " "u='Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir']") assert stream.observed_output.strip() == expected_output
class TeamcityStatisticsReport(pep8.StandardReport): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.teamcity_messages = TeamcityServiceMessages() def report_statistics(self, error_key, value): self.teamcity_messages.message('buildStatisticValue', key='PEP8-'+error_key, value=str(value)) def print_statistics(self, prefix=''): super().print_statistics(prefix) for error_key in sorted(self.messages): self.report_statistics(error_key, self.counters[error_key]) self.report_statistics('TOTAL', self.get_count()) self.report_statistics('TOTAL-ERRORS', self.get_count('E')) self.report_statistics('TOTAL-WARNINGS', self.get_count('W'))
class TeamCityReport(Report): '''TeamCity streaming reporter for a test suite''' def __init__(self, file, info, sync=True, **kwargs): self.messages = TeamcityServiceMessages(file) self.messages.message('compile-info', name=info[0], date=info[1], time=info[2]) self.sync = sync def __call__(self, index, args, info): cls = TeamCityLazyReport if self.sync else TeamCityTestReport return cls(self.messages, args, info[0]) def __enter__(self): self.messages.testSuiteStarted('default-suite') return self def __exit__(self, value, cls, traceback): self.messages.testSuiteFinished('default-suite')
def test_one_property(self): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: datetime.min) messages.message('dummyMessage', fruit='apple') assert stream.observed_output == "\n##teamcity[dummyMessage timestamp='0001-01-01T00:00' fruit='apple']\n"
def test_one_property(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) messages.message('dummyMessage', fruit='apple') assert stream.observed_output == "##teamcity[dummyMessage timestamp='2000-11-02T10:23:01.556' fruit='apple']\n".encode( 'utf-8')
def test_three_properties(self): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: datetime.min) messages.message('dummyMessage', fruit='apple', meat='steak', pie='raspberry') assert stream.observed_output ==\ "\n##teamcity[dummyMessage timestamp='0001-01-01T00:00' fruit='apple' meat='steak' pie='raspberry']\n"
def test_no_properties(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) messages.message('dummyMessage') assert stream.observed_output == "\n##teamcity[dummyMessage timestamp='2000-11-02T10:23:01.556']\n"
def test_three_properties(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) messages.message('dummyMessage', fruit='apple', meat='steak', pie='raspberry') assert stream.observed_output == "\n##teamcity[dummyMessage timestamp='2000-11-02T10:23:01.556' fruit='apple' meat='steak' pie='raspberry']\n".encode('utf-8')
def test_one_property(): stream = StreamStub() messages = TeamcityServiceMessages(output=stream, now=lambda: fixed_date) messages.message('dummyMessage', fruit='apple') assert stream.observed_output == "\n##teamcity[dummyMessage timestamp='2000-11-02T10:23:01.556' fruit='apple']\n".encode('utf-8')