Re: adding a simulation mode

2012-07-13 Thread Chris Angelico
On Sat, Jul 14, 2012 at 3:08 AM, Prasad, Ramit wrote: > I would say the opposite. In production code usually I want it > to recover, log as much information as I need (including sending > any notifications), and NOT just die. > > In development, not catching the exception will give me a full > tra

RE: adding a simulation mode

2012-07-13 Thread Prasad, Ramit
> > Please do NOT catch BaseException, since that is the wrong thing to do. > > I would agree if you had said "in production code". > > If you are investigating why a third-party function is stopping your > interpreter, then catching BaseException may tell you that the code > is raising the wrong

Re: adding a simulation mode

2012-07-13 Thread Hans Mulder
On 13/07/12 04:16:53, Steven D'Aprano wrote: > On Thu, 12 Jul 2012 16:37:42 +0100, andrea crotti wrote: > >> 2012/7/12 John Gordon : >>> In andrea crotti >>> writes: >>> Well that's what I thought, but I can't find any explicit exit anywhere in shutil, so what's going on there? >>> >>>

Re: adding a simulation mode

2012-07-13 Thread andrea crotti
2012/7/13 Steven D'Aprano : > Well of course it does. If copytree fails, the try block ends and > execution skips straight to the except block, which runs, and then the > program halts because there's nothing else to be done. > > That at least is my guess, based on the described symptoms. > Well

Re: adding a simulation mode

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 14:20:18 +0100, andrea crotti wrote: > One thing that I don't quite understand is why some calls even if I > catch the exception still makes the whole program quit. Without seeing your whole program, we can't possibly answer this. But by consulting my crystal ball, I bet you

Re: adding a simulation mode

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 16:37:42 +0100, andrea crotti wrote: > 2012/7/12 John Gordon : >> In andrea crotti >> writes: >> >>> Well that's what I thought, but I can't find any explicit exit >>> anywhere in shutil, so what's going on there? >> >> Try catching SystemExit specifically (it doesn't inherit

Re: adding a simulation mode

2012-07-12 Thread Steven D'Aprano
On Thu, 12 Jul 2012 15:17:03 +0100, andrea crotti wrote: > Well that's what I thought, but I can't find any explicit exit anywhere > in shutil, so what's going on there? Hard to say, since you don't give any context to your question. When replying to posts, please leave enough quoted to establis

Re: adding a simulation mode

2012-07-12 Thread Dieter Maurer
andrea crotti wrote at 2012-7-12 14:20 +0100: >One thing that I don't quite understand is why some calls even if I >catch the exception still makes the whole program quit. >For example this > >try: >copytree('sjkdf', 'dsflkj') >Popen(['notfouhd'], shell=True) >except Excepti

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
2012/7/12 John Gordon : > In andrea crotti > writes: > >> Well that's what I thought, but I can't find any explicit exit >> anywhere in shutil, so what's going on there? > > Try catching SystemExit specifically (it doesn't inherit from Exception, > so "except Exception" won't catch it.) > > --

Re: adding a simulation mode

2012-07-12 Thread John Gordon
In andrea crotti writes: > Well that's what I thought, but I can't find any explicit exit > anywhere in shutil, so what's going on there? Try catching SystemExit specifically (it doesn't inherit from Exception, so "except Exception" won't catch it.) -- John Gordon A is for

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
Well that's what I thought, but I can't find any explicit exit anywhere in shutil, so what's going on there? -- http://mail.python.org/mailman/listinfo/python-list

Re: adding a simulation mode

2012-07-12 Thread John Gordon
In andrea crotti writes: > try: > copytree('sjkdf', 'dsflkj') > Popen(['notfouhd'], shell=True) > except Exception as e: > print("here") > behaves differently from: > try: > Popen(['notfouhd'], shell=True) > copytree('sjkdf', 'dsflkj') >

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
One way instead that might actually work is this def default_mock_action(func_name): def _default_mock_action(*args, **kwargs): print("running {} with args {} and {}".format(func_name, args, kwargs)) return _default_mock_action def mock_fs_actions(to_run): """Take a function

Re: adding a simulation mode

2012-07-12 Thread andrea crotti
One thing that I don't quite understand is why some calls even if I catch the exception still makes the whole program quit. For example this try: copytree('sjkdf', 'dsflkj') Popen(['notfouhd'], shell=True) except Exception as e: print("here") behaves differently f

Re: adding a simulation mode

2012-07-05 Thread andrea crotti
2012/7/5 Dieter Maurer : > > There is a paradigm called "inversion of control" which can be used > to handle those requirements. > > With "inversion of control", the components interact on the bases > of interfaces. The components themselves do not know each other, they > know only the interfaces t

Re: adding a simulation mode

2012-07-05 Thread Dieter Maurer
andrea crotti writes: > I'm writing a program which has to interact with many external > resources, at least: > - mysql database > - perforce > - shared mounts > - files on disk > > And the logic is quite complex, because there are many possible paths to > follow depending on some other parameter

Re: adding a simulation mode

2012-07-04 Thread Paul Rubin
andrea crotti writes: > copytree(src, dest) becomes: > if not PRETEND_ONLY: > copytree(src, dest) > > But I don't like it too much because I would have to add a lot of > garbage around.. I've had good results writing the module under test in the style of a java applet, i.e. one of its args is

Re: adding a simulation mode

2012-07-04 Thread Devin Jeanpierre
For what it's worth, this is the reason that Allen Short wrote Exocet. > This way, you can test your code without having to resort to sys.modules > hackery, and you can better factor your applications by separating > configuration and environment concerns from the rest of your code. See: - http:

Re: adding a simulation mode

2012-07-04 Thread Mike C. Fletcher
On 12-07-04 05:42 AM, andrea crotti wrote: ... copytree(src, dest) becomes: if not PRETEND_ONLY: copytree(src, dest) import globalsub, unittest class MyTest( unittest.TestCase ): def setUp( self ): globalsub.subs( shutil.copytree ) def tearDown( self ): globalsub.re

Re: adding a simulation mode

2012-07-04 Thread andrea crotti
> Yes there is no easy solution apparently.. But I'm also playing > around with vagrant and virtual machine generations, suppose I'm able > to really control what will be on the machine at time X, creating it > on demand with what I need, it might be a good way to solve my > problems (a bit overki

Re: adding a simulation mode

2012-07-04 Thread andrea crotti
2012/7/4 Steven D'Aprano : > > Then, have your code accept the thing as an argument. > > E.g. instead of having a hard-coded database connection, allow the > database connection to be set (perhaps as an argument, perhaps as a > config option, etc.). > > There are libraries to help with mocks, e.g.:

Re: adding a simulation mode

2012-07-04 Thread Steven D'Aprano
On Wed, 04 Jul 2012 10:42:56 +0100, andrea crotti wrote: > I'm writing a program which has to interact with many external > resources, at least: > - mysql database > - perforce > - shared mounts > - files on disk > > And the logic is quite complex, because there are many possible paths to > follo

adding a simulation mode

2012-07-04 Thread andrea crotti
I'm writing a program which has to interact with many external resources, at least: - mysql database - perforce - shared mounts - files on disk And the logic is quite complex, because there are many possible paths to follow depending on some other parameters. This program even needs to run on many