Пример #1
0
def CapturedOutput():
    new_out, new_err = StringIO(), StringIO()
    old_out, old_err = sys.stdout, sys.stderr
    try:
        sys.stdout, sys.stderr = new_out, new_err
        yield sys.stdout, sys.stderr
    finally:
        sys.stdout, sys.stderr = old_out, old_err
Пример #2
0
 def test_download_mirror_list(self):
     tmp = tempfile.NamedTemporaryFile()
     tmp.close()
     progress = StringIO()
     Download(MirrorList.URL, tmp.name, progress=progress).run()
     self.assertEqual(progress.getvalue(),
         '[......................................................................]\n')
     with open(tmp.name, 'r') as f:
         content = f.read()
         self.assertTrue(content.startswith('# Sage Mirror List'))
Пример #3
0
 def test_download_mirror_list(self):
     tmp = tempfile.NamedTemporaryFile()
     tmp.close()
     progress = StringIO()
     Download(MirrorList.URL, tmp.name, progress=progress).run()
     self.assertEqual(
         progress.getvalue(),
         '[......................................................................]\n'
     )
     with open(tmp.name, 'r') as f:
         content = f.read()
         self.assertTrue(content.startswith('# Sage Mirror List'))
Пример #4
0
 def test_error(self):
     URL = 'http://www.sagemath.org/sage_bootstrap/this_url_does_not_exist'
     progress = StringIO()
     download = Download(URL, progress=progress)
     log = CapturedLog()
     def action():
         with log:
             download.run()
     self.assertRaises(IOError, action)
     self.assertIsNotFoundError(log.messages())
     self.assertEqual(progress.getvalue(),
         '[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]\n')
Пример #5
0
    def test_error(self):
        URL = 'http://files.sagemath.org/sage_bootstrap/this_url_does_not_exist'
        progress = StringIO()
        download = Download(URL, progress=progress)
        log = CapturedLog()

        def action():
            with log:
                download.run()

        self.assertRaises(IOError, action)
        self.assertIsNotFoundError(log.messages())
        self.assertEqual(
            progress.getvalue(),
            '[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]\n'
        )