GitXplorerGitXplorer
r

python-syringe

public
1 stars
2 forks
0 issues

Commits

List of commits on branch master.
Verified
6cd66a68bed67a0f86a84abd24fe2ef712cc0459

Bump to version 0.4.0

rremcohaszing committed 7 years ago
Verified
e4397199d4922f7f41d81903fd9f901694c70520

Merge pull request #2 from siebz0r/feat_inheritance_pr

rremcohaszing committed 7 years ago
Unverified
ee8d86226b90ee04de4b2960a84190f95e661c83

Don't mark subclass as duplicate provider

ddcsiebe committed 7 years ago
Unverified
6b404d4bdfde688e98eab6c2cd8a490d7af57f58

Rename faulty ___init__ to __init__

ddcsiebe committed 7 years ago
Unverified
a372416f846ab3b20b97c87f43bf1827a9b60136

Implement PEP 246 compliant environment markers

rremcohaszing committed 10 years ago
Unverified
4f81ff68ab7946b2ee1878bceac129860984b439

Update .gitignore to match the latest setuptools

rremcohaszing committed 10 years ago

README

The README file for this repository.

======= Syringe

.. image:: https://travis-ci.org/remcohaszing/grunt-angular-templatecache.png?branch=master :target: https://travis-ci.org/remcohaszing/python-audiolayer

A simple dependency injection library.

Usage example

First decorate a class with @provides('a lookup name').

import syringe

@syringe.provides('cure') ... class Syrup: ... def drink(self, person): ... print('Nom nom') ... person.health = 100 ...

Instantiate it. Note that it is not possible to instanciate another instance of a class decorated with the name cure.

syrup = Syrup()

Next inject it in another class using inject('a lookup name').

class Person: ... cure = syringe.inject('cure') ... ... def drink_medicine(self): ... self.cure.drink(self) ...

When an instance of the Person class is created, the value of the injecte name is the instance of the provided and instantiated class.

person = Person() person.health = 20 assert person.cure == syrup person.drink_medicine() Nom nom assert person.health == 100

Mocking

A mock instance can be inserted using syringe.mock('a lookup name')

try: ... from unittest import mock ... except: ... import mock ... m = syringe.mock('cure') person.drink_medicine() m.drink.assert_called_once_with(person)

Installing

The package can be installed from the cheese shop by typing::

pip install syringe