Sha256: 80b7bf01869f25abfe6d963726bed3c1845d3805653c49a5b9bc9935a6bc9a11

Contents?: true

Size: 1.35 KB

Versions: 12

Compression:

Stored size: 1.35 KB

Contents

require File.dirname(__FILE__) + '/spec_helper.rb'

describe RubyPython::PythonError do
  def cause_error
    RubyPython::Python.PyImport_ImportModule("wat")
  end

  describe "#error?" do
    it "should return false when no error has occured" do
      described_class.error?.should be_false
    end

    it "should return true when an error has occured" do
      cause_error
      described_class.error?.should be_true
    end
  end

  describe "#clear" do
    it "should reset the Python error flag" do
      cause_error
      described_class.clear
      described_class.error?.should be_false
    end

    it "should not barf when there is no error" do
      lambda {described_class.clear}.should_not raise_exception
    end
  end

  describe "#fetch" do
    it "should make availible Python error type" do
      cause_error
      rbType, rbValue, rbTraceback = described_class.fetch
      rbType.getAttr("__name__").rubify.should == "ImportError"
    end
  end

  describe ".last_traceback" do
    it "should make availble the Python traceback of the last error" do
      traceback = RubyPython.import 'traceback'
      errors = RubyPython.import 'errors'
      begin
        errors.nested_error
      rescue RubyPython::PythonError => exc
        tb = exc.traceback
        list = traceback.format_tb(tb)
        list.rubify[0].should =~ /1 \/ 0/
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
lokeshh_rubypython-0.7.1 spec/pythonerror_spec.rb
lokeshh_rubypython-0.7 spec/pythonerror_spec.rb
rubypython-0.6.4 spec/pythonerror_spec.rb
rubypython-0.6.3 spec/pythonerror_spec.rb
rubypython-raspi-0.1.2 spec/pythonerror_spec.rb
rubypython-raspi-0.1.1 spec/pythonerror_spec.rb
rubypython-raspi-0.1.0 spec/pythonerror_spec.rb
rubypython-0.6.2 spec/pythonerror_spec.rb
rubypython-0.6.1 spec/pythonerror_spec.rb
rubypython-0.6.0 spec/pythonerror_spec.rb
rubypython-0.5.3 spec/pythonerror_spec.rb
rubypython-0.5.2 spec/pythonerror_spec.rb