This repository was archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpythonerror_spec.rb
More file actions
52 lines (45 loc) · 1.35 KB
/
Copy pathpythonerror_spec.rb
File metadata and controls
52 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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