コード例 #1
0
    def testCPURuby(self):
        """Should be able to catch CPU Exception (in Ruby)."""

        # This test intentionally takes a few seconds to run.

        # Code is originally from
        # https://scraperwiki.com/scrapers/cpu-rb/edit/
        code = """
Process.setrlimit(Process::RLIMIT_CPU, 1, 2)

x = 2
begin
  while true do
    a = x**x
  end
rescue ScraperWiki::Error => ex
  if ex.message.match('CPU')
    puts "CPU exception caught"
  else
    puts "Error, unexpected exception"
  end
end
"""

        stuff = self.Execute(code, language='ruby')
        output = testbase.console(stuff)
        assert 'CPU exception' in output
コード例 #2
0
 def testUnicodeOutput(self):
     """Should be able to see some unicode output."""
     stuff = self.Execute(r"""print u'\N{left-pointing double angle quotation mark}hello'""", language="python")
     output = testbase.console(stuff)
     # Note that left-pointing double angle quotation mark is
     # U+00AB.
     assert u"\xabhello" in output
コード例 #3
0
    def testCPUPython(self):
        """Should be able to catch CPU Exception (in Python)."""

        # This test intentionally takes a few seconds to run.

        # code is originally from
        # https://scraperwiki.com/scrapers/cpu-py_1/edit/
        code = """
import resource
import scraperwiki
import sys

# We artificially lower the soft CPU limit to 2 seconds, so that we
# can run this scraper and see the exception in reasonable time.
resource.setrlimit(resource.RLIMIT_CPU, (2, 4))

# A loop that consumes CPU
a=2
try:
    while True:
        print a
        a = a*a
except scraperwiki.Error as e:
    if 'CPU' in str(e):
        print "CPU exception caught"
    else:
        print "Error, unexpected exception"

"""

        stuff = self.Execute(code)
        output = testbase.console(stuff)
        assert 'CPU exception' in output
コード例 #4
0
 def testNotUTF8(self):
     """Should be able to see some output, even when not UTF-8."""
     # Note that the script intentionally prints something
     # that is not a valid UTF-8 stream.
     stuff = self.Execute(r"""print '\xabHello'""")
     output = testbase.console(stuff)
     assert "Hello" in output
コード例 #5
0
ファイル: testconsole.py プロジェクト: imclab/ScraperWikiX
 def testNotUTF8(self):
     """Should be able to see some output, even when not UTF-8."""
     # Note that the script intentionally prints something
     # that is not a valid UTF-8 stream.
     stuff = self.Execute(r"""print '\xabHello'""")
     output = testbase.console(stuff)
     assert 'Hello' in output
コード例 #6
0
ファイル: testcore.py プロジェクト: imclab/ScraperWikiX
    def testCPURuby(self):
        """Should be able to catch CPU Exception (in Ruby)."""

        # This test intentionally takes a few seconds to run.

        # Code is originally from
        # https://scraperwiki.com/scrapers/cpu-rb/edit/
        code = """
Process.setrlimit(Process::RLIMIT_CPU, 1, 2)

x = 2
begin
  while true do
    a = x**x
  end
rescue ScraperWiki::Error => ex
  if ex.message.match('CPU')
    puts "CPU exception caught"
  else
    puts "Error, unexpected exception"
  end
end
"""

        stuff = self.Execute(code, language='ruby')
        output = testbase.console(stuff)
        assert 'CPU exception' in output
コード例 #7
0
ファイル: testcore.py プロジェクト: imclab/ScraperWikiX
    def testCPUPython(self):
        """Should be able to catch CPU Exception (in Python)."""

        # This test intentionally takes a few seconds to run.

        # code is originally from
        # https://scraperwiki.com/scrapers/cpu-py_1/edit/
        code = """
import resource
import scraperwiki
import sys

# We artificially lower the soft CPU limit to 2 seconds, so that we
# can run this scraper and see the exception in reasonable time.
resource.setrlimit(resource.RLIMIT_CPU, (2, 4))

# A loop that consumes CPU
a=2
try:
    while True:
        print a
        a = a*a
except scraperwiki.Error as e:
    if 'CPU' in str(e):
        print "CPU exception caught"
    else:
        print "Error, unexpected exception"

"""

        stuff = self.Execute(code)
        output = testbase.console(stuff)
        assert 'CPU exception' in output
コード例 #8
0
ファイル: testconsole.py プロジェクト: imclab/ScraperWikiX
 def testUnicodeOutput(self):
     """Should be able to see some unicode output."""
     stuff = self.Execute(
         r"""print u'\N{left-pointing double angle quotation mark}hello'""",
         language='python')
     output = testbase.console(stuff)
     # Note that left-pointing double angle quotation mark is
     # U+00AB.
     assert u'\xabhello' in output
コード例 #9
0
 def testPython(self):
     """Should be able to run Python code."""
     stuff = self.Execute(
       """print 'hell'+'o'*3""", language='python')
     output = testbase.console(stuff)
     assert 'hellooo' in output
コード例 #10
0
ファイル: testcore.py プロジェクト: imclab/ScraperWikiX
 def testPython(self):
     """Should be able to run Python code."""
     stuff = self.Execute("""print 'hell'+'o'*3""", language='python')
     output = testbase.console(stuff)
     assert 'hellooo' in output