mardi 20 septembre 2016

Mocking ConfigObj instances

Using ConfigObj, I want to test some section creation code:

def create_section(config, section):
    config.reload()
    if section not in config:
         config[session] = {}
         logging.info("Created new section %s.", section)
    else:
         logging.debug("Section %s already exists.", section)

I would like to write a few unit tests but I am hitting a problem. For example,

def test_create_section_created():
    config = Mock(spec=ConfigObj)  # ← This is not right…
    create_section(config, 'ook')
    assert 'ook' in config
    config.reload.assert_called_once_with()

Clearly, the test method will fail because of a TypeError as the argument of type 'Mock' is not iterable.

How can I define the config object as a mock?

2 commentaires:

  1. Did you know there is a 12 word phrase you can tell your man... that will induce deep feelings of love and impulsive attractiveness for you deep inside his heart?

    That's because hidden in these 12 words is a "secret signal" that triggers a man's impulse to love, worship and care for you with his entire heart...

    ===> 12 Words Who Trigger A Man's Love Instinct

    This impulse is so built-in to a man's mind that it will drive him to work harder than ever before to build your relationship stronger.

    Matter-of-fact, fueling this influential impulse is absolutely essential to having the best ever relationship with your man that the instance you send your man one of these "Secret Signals"...

    ...You'll instantly find him open his heart and soul to you in a way he haven't experienced before and he will distinguish you as the only woman in the universe who has ever truly fascinated him.

    RépondreSupprimer
  2. stainless steel titanium nitride coating - TITA
    Stainless steel titanium nitride coating - TITA. TITA, the TEN, titanium necklace is a ceramic-art stainless steel titanium body armor structure, made 2017 ford focus titanium from babyliss pro nano titanium hair dryer a titanium-iron-art stainless steel titanium trim hair cutter core that is used

    RépondreSupprimer