raise

How do I subscribe to raised events and printing together?

时光毁灭记忆、已成空白 提交于 2019-12-23 17:38:06
问题 I have been working on a program that has 3 classes of which 2 of the classes have timers that repeat at different intervals and once one "cycle" of the timer is done it raises an event with a string as return. The 3rd class subscribes to the events from the other two timer classes and prints them to screen. it works great! But my issue is that it is printing them separately. Lets say that the first timer class runs and then raises "hello" every 2 minutes and the other class "dog" every

Ruby Kernel.raise method throws error when enclosing parameters in parenthesis

限于喜欢 提交于 2019-12-20 04:50:16
问题 I like method parameters enclosed in parenthesis, this is some Pascal nostalgia. When cleaning up code, if I find a method parameters without it I enclose them immediately. Today it caused my working code throwing errors although my syntax looks okay according to the documentation. Kernel.raise's documentation has this format: (Object) raise(exception[, string [, array]]) These are all working: > raise TypeError TypeError: TypeError > raise (TypeError) TypeError: TypeError > raise "Error

Ruby Kernel.raise method throws error when enclosing parameters in parenthesis

烂漫一生 提交于 2019-12-20 04:49:01
问题 I like method parameters enclosed in parenthesis, this is some Pascal nostalgia. When cleaning up code, if I find a method parameters without it I enclose them immediately. Today it caused my working code throwing errors although my syntax looks okay according to the documentation. Kernel.raise's documentation has this format: (Object) raise(exception[, string [, array]]) These are all working: > raise TypeError TypeError: TypeError > raise (TypeError) TypeError: TypeError > raise "Error

How to cancel evaluating a required Ruby file?

最后都变了- 提交于 2019-12-19 14:06:28
问题 file1 requires file2 , and I want to be able to cancel evaluating file2 under certain conditions without exiting the whole process. # file1.rb puts "In file 1" require 'file2' puts "Back in file 1" # file2.rb puts "In file 2" # return if some_conditional puts "Still in file 2" When running file1 , the output I want to see is: In file 1 In file 2 Back in file 1 The goal is for Still in file 2 to never print, while Back in file 1 does print. Is there anything I can do in file2 to make this

How to cancel evaluating a required Ruby file?

拥有回忆 提交于 2019-12-19 14:06:03
问题 file1 requires file2 , and I want to be able to cancel evaluating file2 under certain conditions without exiting the whole process. # file1.rb puts "In file 1" require 'file2' puts "Back in file 1" # file2.rb puts "In file 2" # return if some_conditional puts "Still in file 2" When running file1 , the output I want to see is: In file 1 In file 2 Back in file 1 The goal is for Still in file 2 to never print, while Back in file 1 does print. Is there anything I can do in file2 to make this

How to use pytest to check that Error is NOT raised

风格不统一 提交于 2019-12-18 12:44:45
问题 Let's assume we have smth like that : import py, pytest ERROR1 = ' --- Error : value < 5! ---' ERROR2 = ' --- Error : value > 10! ---' class MyError(Exception): def __init__(self, m): self.m = m def __str__(self): return self.m def foo(i): if i < 5: raise MyError(ERROR1) elif i > 10: raise MyError(ERROR2) return i # ---------------------- TESTS ------------------------- def test_foo1(): with pytest.raises(MyError) as e: foo(3) assert ERROR1 in str(e) def test_foo2(): with pytest.raises

How to use pytest to check that Error is NOT raised

与世无争的帅哥 提交于 2019-12-18 12:44:22
问题 Let's assume we have smth like that : import py, pytest ERROR1 = ' --- Error : value < 5! ---' ERROR2 = ' --- Error : value > 10! ---' class MyError(Exception): def __init__(self, m): self.m = m def __str__(self): return self.m def foo(i): if i < 5: raise MyError(ERROR1) elif i > 10: raise MyError(ERROR2) return i # ---------------------- TESTS ------------------------- def test_foo1(): with pytest.raises(MyError) as e: foo(3) assert ERROR1 in str(e) def test_foo2(): with pytest.raises

Difference between Raise Try and Assert

巧了我就是萌 提交于 2019-12-18 10:33:37
问题 I have been learning Python for a while and the raise function and assert are (what I realised is that both of them crash the app, unlike try - except) really similar and I can't see a situation where you would use raise or assert over try . So, what is the difference between Raise, Try and Assert? 回答1: Assert: Used when you want to "stop" the script based on a certain condition and return something to help debug faster: list_ = ["a","b","x"] assert "x" in list_, "x is not in the list" print(

Rails ActiveSupport: How to assert that an error is raised?

六眼飞鱼酱① 提交于 2019-12-18 03:01:25
问题 I am wanting to test a function on one of my models that throws specific errors. The function looks something like this: def merge(release_to_delete) raise "Can't merge a release with itself!" if( self.id == release_to_delete.id ) raise "Can only merge releases by the same artist" if( self.artist != release_to_delete.artist ) #actual merge code here end Now I want to do an assert that when I call this function with a parameter that causes each of those exceptions, that the exceptions actually

how to raise an event when a value in a cell of a wpf datagrid changes using MVVM?

旧街凉风 提交于 2019-12-10 16:57:53
问题 I need help with a wpf datagrid using the MVVM design pattern. I have a datagid that is bound to an observablecollection. The first column in the grid contains decimal values that cannot be edited. The second column contains a textbox into which a decimal value must be entered. The third column must display the difference between the value in the first column and the value in the second column AS IT IS ENTERED. I was hoping that handling the observablecollection's Collectionchanged event will