Git Product home page Git Product logo

Comments (4)

wesalvaro avatar wesalvaro commented on April 27, 2024

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 Nones. It's more explicit and clearer than getting AttributeErrors on Nones.

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.

yozo1984 avatar yozo1984 commented on April 27, 2024

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.

wesalvaro avatar wesalvaro commented on April 27, 2024

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.

wesalvaro avatar wesalvaro commented on April 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.