def with_class_and_partial_match(model_class, instances): matches = list( utilities.match( model_class, kind='spam', ) ) expect(len(matches)) == 2 for instance in matches: expect(instance.kind) == 'spam' expect(instances).contains(instance)
def with_self_string_and_partial_match(model_class, instances): matches = list( utilities.match( "data/{self.kind}/{self.key}.yml", (lambda key, kind: model_class(kind, key, test="test")), kind='egg', ) ) expect(len(matches)) == 2 for instance in matches: expect(instance.kind) == 'egg' expect(instances).contains(instance)
def with_class_and_no_factory(model_class, instances): matches = list( utilities.match( model_class, kind='spam', key='foo', ) ) expect(len(matches)) == 1 instance = matches[0] expect(instance.kind) == 'spam' expect(instance.key) == 'foo' expect(instances).contains(instance)
def with_self_string(model_class, instances): matches = list( utilities.match( "data/{self.kind}/{self.key}.yml", (lambda key, kind: model_class(kind, key, test="test")), kind='spam', key='bar', ) ) expect(len(matches)) == 1 instance = matches[0] expect(instance.kind) == 'spam' expect(instance.key) == 'bar' expect(instances).contains(instance)
def with_class_and_factory(model_class, instances): matches = list( utilities.match( model_class, (lambda key, kind: model_class(kind, key, test="test")), kind='spam', key='foo', ) ) expect(len(matches)) == 1 instance = matches[0] expect(instance.kind) == 'spam' expect(instance.key) == 'foo' expect(instances).contains(instance)
def it_is_not_yet_implemented(): with expect.raises(NotImplementedError): utilities.match(Mock)
def match(cls, *args, **kwargs): return utilities.match(cls, *args, **kwargs)