How best to test functions which use date.today

2009-02-28 Thread Yuan HOng
HI, In my project I have several date related methods which I want tested for correctness. The functions use date.today() in several places. Since this could change every time I run the test, I hope to find someway to fake a date.today. For illustration lets say I have a function: from datetime

Re: How best to test functions which use date.today

2009-03-02 Thread Yuan HOng
Hello, Thanks for all the great ideas. Based on your input, I was able to solve my problem by way of a FakeDate in a fakedate module. In the testing module, before importing the tested module, I would load my fakedate module into sys.modules under the key 'datetime'. So when the tested module is

Re: How best to test functions which use date.today

2009-03-03 Thread Ed Singleton
On Feb 28, 5:54 pm, Lie Ryan wrote: > Yuan HOng wrote: > > HI, > > > In my project I have several date related methods which I want tested for > > correctness. The functions use date.today() in several places. Since this > > could change every time I run the test, I hope to find someway to fake a

Re: How best to test functions which use date.today

2009-02-28 Thread Lie Ryan
Yuan HOng wrote: HI, In my project I have several date related methods which I want tested for correctness. The functions use date.today() in several places. Since this could change every time I run the test, I hope to find someway to fake a date.today. For illustration lets say I have a functi

Re: How best to test functions which use date.today

2009-02-28 Thread Christian Heimes
Lie Ryan wrote: >> But this fails with: >> >> TypeError: can't set attributes of built-in/extension type >> 'datetime.date' > > This is because today is an attribute. In python, we can override > attribute access to become a function call. I don't have python right > now, but try this: > > del da

Re: How best to test functions which use date.today

2009-02-28 Thread rdmurray
Christian Heimes wrote: > Lie Ryan wrote: > >> But this fails with: > >> > >> TypeError: can't set attributes of built-in/extension type > >> 'datetime.date' > > > > This is because today is an attribute. In python, we can override > > attribute access to become a function call. I don't have pyth

Re: How best to test functions which use date.today

2009-02-28 Thread Gabriel Genellina
En Sat, 28 Feb 2009 15:35:47 -0200, Yuan HOng escribió: In my project I have several date related methods which I want tested for correctness. The functions use date.today() in several places. Since this could change every time I run the test, I hope to find someway to fake a date.today. For

Re: How best to test functions which use date.today

2009-02-28 Thread Scott David Daniels
Lie Ryan wrote: Yuan HOng wrote: In my project I have several date related methods which I want tested for correctness. The functions use date.today() in several places. Since this could change every time I run the test, I hope to find someway to fake a date.today. For illustration lets say I ha