def test_is_partial_test_cls(): class NotAPartialTemplateTest(object): pass class NotAPartialTemplateTest2(PartialTemplateTestCase): pass class IsAPartialTemplateTest(PartialTemplateTestCase): partial = 'testing.templates.src.partial_template_no_arguments' method = 'render' assert not is_partial_test_cls(PartialTemplateTestCase) assert not is_partial_test_cls(NotAPartialTemplateTest) assert not is_partial_test_cls(NotAPartialTemplateTest2) assert is_partial_test_cls(IsAPartialTemplateTest)
def test_partial_template(self): # Local import to avoid circular dependency from Cheetah.testing.all_partials_tested import is_partial_test_cls # XXX: apparently pytest likes to discover and run this case when # imported if not is_partial_test_cls(type(self)): return if self.partial is None: raise AssertionError(b'Partial name not set on instance') if self.method is None: raise AssertionError(b'Partial method name not set on instance') template = self.instantiate_template_instance() partial_module = __import__( self.partial, fromlist=['__trash'], level=0, ) partial_func = getattr(partial_module, self.method) partial_args, partial_kwargs = self.get_partial_arguments() ret = self.call_partial_template( template, partial_func, partial_args, partial_kwargs, ) self.assert_partial_rendering( pyquery.PyQuery( '<div>{0}</div>'.format(ret or ''), parser='html_fragments', ), partial_args, partial_kwargs, )
def test_partial_template(self): # Local import to avoid circular dependency from Cheetah.testing.all_partials_tested import is_partial_test_cls # XXX: apparently pytest likes to discover and run this case when # imported if not is_partial_test_cls(type(self)): return if self.partial is None: raise AssertionError(b'Partial name not set on instance') if self.method is None: raise AssertionError(b'Partial method name not set on instance') template = self.instantiate_template_instance() partial_module = __import__( self.partial, fromlist=['__trash'], level=0, ) partial_func = getattr(partial_module, self.method) partial_args, partial_kwargs = self.get_partial_arguments() ret = self.call_partial_template( template, partial_func, partial_args, partial_kwargs, ) self.assert_partial_rendering( pyquery.PyQuery( '<div>{}</div>'.format(ret or ''), parser='html_fragments', ), partial_args, partial_kwargs, )
def test_all_partials_tested_can_fail(): predicate = lambda cls: ( is_partial_test_cls(cls) and 'Template' not in cls.__name__ ) class AllPartialsTestedFailing(TestAllPartialsTestedBase): test_packages = (tests,) template_packages = (testing.templates,) is_partial_test_cls = staticmethod(predicate) with pytest.raises(AssertionError): AllPartialsTestedFailing(methodName='test').test()
def test_get_partial_tests_with_filter(): from tests.testing import partial_template_test_case_test as P predicate = lambda cls: ( is_partial_test_cls(cls) and 'Template' not in cls.__name__ ) ret = set(get_partial_tests((tests,), test_match_func=predicate)) assert ret == set(( ( P.SamplePartialWithSameNameTest, 'testing.templates.src.partial_with_same_name', 'partial_with_same_name', ), ))
def test_partial_template(self): # Local import to avoid circular dependency from Cheetah.testing.all_partials_tested import is_partial_test_cls # XXX: apparently pytest likes to discover and run this case when # imported if not is_partial_test_cls(type(self)): return if self.partial is None: raise AssertionError(b'Partial name not set on instance') if self.method is None: raise AssertionError(b'Partial method name not set on instance') template = self.instantiate_template_instance() partial_module = __import__( self.partial, fromlist=['__trash'], level=0, ) if not hasattr(partial_module, 'PARTIAL_TEMPLATE_CLASS'): raise AssertionError( 'Module {} does not look like a partial template!\n' 'Do you have "#extends Cheetah.partial_template" at the top of your template file?'.format( partial_module, ), ) partial_func = getattr(partial_module, self.method) partial_args, partial_kwargs = self.get_partial_arguments() ret = self.call_partial_template( template, partial_func, partial_args, partial_kwargs, ) self.assert_partial_rendering( pyquery.PyQuery( '<div>{}</div>'.format(ret or ''), parser='html_fragments', ), partial_args, partial_kwargs, )
def predicate(cls): return is_partial_test_cls(cls) and 'Template' not in cls.__name__
def predicate(cls): return is_partial_test_cls(cls) and 'Template' not in cls.__name__