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
 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
    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
 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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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
 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
Beispiel #10
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