コード例 #1
0
    def test_zero_node(self):
        s = BytesIO()
        node = Node('zero', {}, 0)
        with StreamingXMLWriter(s) as writer:
            writer.serialize(node)
        self.assertEqual(s.getvalue(), b'''\
<?xml version="1.0" encoding="utf-8"?>
<zero>
    0
</zero>
''')
コード例 #2
0
 def test_memory(self):
     # make sure the memory occupation is low
     # (to protect against bad refactoring of the XMLWriter)
     pid = os.getpid()
     try:
         rss = memory_rss(pid)
     except psutil.AccessDenied:
         raise unittest.SkipTest('Memory info not accessible')
     devnull = open(os.devnull, 'wb')
     with StreamingXMLWriter(devnull) as writer:
         for asset in assetgen(1000):
             writer.serialize(asset)
     allocated = memory_rss(pid) - rss
     self.assertLess(allocated, 256000)  # < 250 KB
コード例 #3
0
 def test_memory(self):
     # make sure the memory occupation is low
     # (to protect against bad refactoring of the XMLWriter)
     try:
         import psutil
     except ImportError:
         raise unittest.SkipTest('psutil not installed')
     proc = psutil.Process(os.getpid())
     try:
         rss = memory_info(proc).rss
     except psutil.AccessDenied:
         raise unittest.SkipTest('Memory info not accessible')
     devnull = open(os.devnull, 'wb')
     with StreamingXMLWriter(devnull) as writer:
         for asset in assetgen(1000):
             writer.serialize(asset)
     allocated = memory_info(proc).rss - rss
     self.assertLess(allocated, 204800)  # < 200 KB