Comments (4)
That would be quite simple:
import ioc
ioc.EnableTestMode() # Essentially just sets IN to None
import subject
But what's the issue with the current approach? I don't think None
is an acceptable value for injected objects. Since you can override injected values with the call's args, I don't even see a need to change the behavior of the injection, but only warn if a value is being injected in test mode as it is even conceivable that injections would be desired in test mode. I think that this makes more sense than injecting None
s. It's more explicit and clearer than getting AttributeError
s on None
s.
import ioc
import subject
def setUp():
ioc.EnableTestMode() # Enables injection checking + creates TestInjectionsOK.
class Test:
def testA(self):
subject.foo(a=3, b=4) # All injections are injected, OK
def testB(self):
with self.assertRaises(InjectionDuringTestError):
subject.foo(a=3) # injected b is not overridden, so throws
def testC(self):
with ioc.TestInjectionsOK:
subject.foo(a=3) # OK to inject b
from dpy.
I like the idea of EnableTestMode
and do all the checking and what not. A little bit hesitate on the TestInjectionsOK
. Isn't that equal to not calling EnableTestMode
?
from dpy.
Yes, it would be equivalent to temporarily turning off the checks for a
certain injection(s). But I'm totally cool with leaving it out, especially
until we see the need.
On Jul 23, 2013 6:05 PM, "Zak Tsai" [email protected] wrote:
I like the idea of EnableTestMode and do all the checking and what not. A
little bit hesitate on the TestInjectionsOK. Isn't that equal to not
calling EnableTestMode?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/11#issuecomment-21457495
.
from dpy.
Alternatively, a la Guice, you could pull an injection out of the scope for use in your tests if you want and that could be allowed.
from dpy.
Related Issues (13)
- Classes can't be eager or singletons
- Should we make Eager an argument of @Singleton? HOT 3
- should allow name redefinition for @Injectable function HOT 1
- Should be able to debug where the injection comes from. HOT 1
- should be able to do singleton on class injection. HOT 2
- Should have a best practice example for conditional injection. HOT 3
- Classes without `__init__` should still be injectable
- Scopes should be thread safe.
- Tests need to be added.
- Injectables with same name should raise exception even in different scope HOT 4
- Should have better example and README <eom> HOT 1
- Error should be raised if not all injectable arguments are provided. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dpy.