示例#1
0
def test_warn_match():
    if not hasattr(nt, 'assert_logs'):
        raise SkipTest("Test requires nose.tests.assert_logs")
    class A(LoggingConfigurable):
        foo = Integer(config=True)
        bar = Integer(config=True)
        baz = Integer(config=True)
    
    logger = logging.getLogger('test_warn_match')
    
    cfg = Config({'A': {'bat': 5}})
    with nt.assert_logs(logger, logging.WARNING) as captured:
        a = A(config=cfg, log=logger)
    
    output = '\n'.join(captured.output)
    nt.assert_in('Did you mean one of: `bar, baz`?', output)
    nt.assert_in('Config option `bat` not recognized by `A`.', output)

    cfg = Config({'A': {'fool': 5}})
    with nt.assert_logs(logger, logging.WARNING) as captured:
        a = A(config=cfg, log=logger)
    
    output = '\n'.join(captured.output)
    nt.assert_in('Config option `fool` not recognized by `A`.', output)
    nt.assert_in('Did you mean `foo`?', output)

    cfg = Config({'A': {'totally_wrong': 5}})
    with nt.assert_logs(logger, logging.WARNING) as captured:
        a = A(config=cfg, log=logger)

    output = '\n'.join(captured.output)
    nt.assert_in('Config option `totally_wrong` not recognized by `A`.', output)
    nt.assert_not_in('Did you mean', output)
示例#2
0
def test_warn_match():
    if not hasattr(nt, 'assert_logs'):
        raise SkipTest("Test requires nose.tests.assert_logs")

    class A(LoggingConfigurable):
        foo = Integer(config=True)
        bar = Integer(config=True)
        baz = Integer(config=True)

    logger = logging.getLogger('test_warn_match')

    cfg = Config({'A': {'bat': 5}})
    with nt.assert_logs(logger, logging.WARNING) as captured:
        a = A(config=cfg, log=logger)

    output = '\n'.join(captured.output)
    nt.assert_in('Did you mean one of: `bar, baz`?', output)
    nt.assert_in('Config option `bat` not recognized by `A`.', output)

    cfg = Config({'A': {'fool': 5}})
    with nt.assert_logs(logger, logging.WARNING) as captured:
        a = A(config=cfg, log=logger)

    output = '\n'.join(captured.output)
    nt.assert_in('Config option `fool` not recognized by `A`.', output)
    nt.assert_in('Did you mean `foo`?', output)

    cfg = Config({'A': {'totally_wrong': 5}})
    with nt.assert_logs(logger, logging.WARNING) as captured:
        a = A(config=cfg, log=logger)

    output = '\n'.join(captured.output)
    nt.assert_in('Config option `totally_wrong` not recognized by `A`.',
                 output)
    nt.assert_not_in('Did you mean', output)
示例#3
0
 async def test_no_data(self) -> None:
     self.assert_sensor_equals('capture-block-state', '{}')
     await self.client.request('capture-init', self.cbid)
     self.assert_sensor_equals('capture-block-state',
                               '{"%s": "CAPTURING"}' % self.cbid)
     with assert_logs('katsdpdatawriter.flag_writer', 'WARNING'):
         await self.client.request('capture-done', self.cbid)
     self.assert_sensor_equals('capture-block-state', '{}')
示例#4
0
 async def test_context_manager_no_ready(self) -> None:
     """Test using :class:`resource.ResourceAllocation` as a context \
     manager when the user does not call :meth:`.ResourceAllocation.ready`."""
     with assert_logs('katsdpsigproc.resource', logging.WARNING) as cm:
         r = resource.Resource(None, loop=self.loop)
         a0 = r.acquire()
         with a0:
             pass
     assert_equal(
         cm.output,
         ['WARNING:katsdpsigproc.resource:Resource allocation was not explicitly made ready'])
示例#5
0
 def test_log_bad_config(self):
     if not hasattr(nt, 'assert_logs'):
         raise SkipTest("Test requires nose.tests.assert_logs")
     app = MyApp()
     app.log = logging.getLogger()
     name = 'config.py'
     with TemporaryDirectory() as td:
         with open(pjoin(td, name), 'w') as f:
             f.write("syntax error()")
         with nt.assert_logs(app.log, logging.ERROR) as captured:
             app.load_config_file(name, path=[td])
     output = '\n'.join(captured.output)
     self.assertIn('SyntaxError', output)
示例#6
0
 def test_log_bad_config(self):
     if not hasattr(nt, 'assert_logs'):
         raise SkipTest("Test requires nose.tests.assert_logs")
     app = MyApp()
     app.log = logging.getLogger()
     name = 'config.py'
     with TemporaryDirectory() as td:
         with open(pjoin(td, name), 'w') as f:
             f.write("syntax error()")
         with nt.assert_logs(app.log, logging.ERROR) as captured:
             app.load_config_file(name, path=[td])
     output = '\n'.join(captured.output)
     self.assertIn('SyntaxError', output)
示例#7
0
 def test_disallow_unsized_heaps(self):
     """Packets without heap length rejected if disallowed"""
     packet = self.flavour.make_packet([
         Item(spead2.HEAP_CNT_ID, 1, True),
         Item(0x1000, None, False, offset=0),
         Item(spead2.PAYLOAD_OFFSET_ID, 0, True),
         Item(spead2.PAYLOAD_LENGTH_ID, 64, True)
     ], bytes(np.arange(0, 64, dtype=np.uint8).data))
     with assert_logs('spead2', 'INFO') as cm:
         heaps = self.data_to_heaps(packet, allow_unsized_heaps=False)
         # Logging is asynchronous, so we have to give it a bit of time
         time.sleep(0.1)
     assert_equal(
         cm.output,
         ['INFO:spead2:packet rejected because it has no HEAP_LEN'])
     assert_equal(0, len(heaps))
示例#8
0
 def test_disallow_unsized_heaps(self):
     """Packets without heap length rejected if disallowed"""
     packet = self.flavour.make_packet(
         [
             Item(spead2.HEAP_CNT_ID, 1, True),
             Item(0x1000, None, False, offset=0),
             Item(spead2.PAYLOAD_OFFSET_ID, 0, True),
             Item(spead2.PAYLOAD_LENGTH_ID, 64, True)
         ], bytes(np.arange(0, 64, dtype=np.uint8).data))
     if assert_logs is not None:
         with assert_logs('spead2', 'INFO') as cm:
             heaps = self.data_to_heaps(packet, allow_unsized_heaps=False)
             # Logging is asynchronous, so we have to give it a bit of time
             time.sleep(0.1)
         assert_equal(cm.output, ['INFO:spead2:packet rejected because it has no HEAP_LEN'])
     else:
         # Python 2 fallback
         heaps = self.data_to_heaps(packet, allow_unsized_heaps=False)
     assert_equal(0, len(heaps))
示例#9
0
 def test_max_chunk_vis_small(self):
     self._make_fake_dataset()
     with assert_logs(logger='katsdpimager.loader_katdal', level=logging.WARNING) as cm:
         self._test_data(max_chunk_vis=1)
     assert_in('Chunk size is 4 dumps but only 1 loaded at a time', cm.records[0].message)
示例#10
0
 async def test_data_after_done(self) -> None:
     await self.client.request('capture-init', self.cbid)
     await self.client.request('capture-done', self.cbid)
     with assert_logs('katsdpdatawriter.flag_writer', 'WARNING') as cm:
         await self.send_heap(self.tx[0], self.ig.get_heap())
     assert_regex(cm.output[0], 'outside of init/done')