def test_convenience_clear_not_initialized(): # This test is put near the top of this module, or at least before # the very first time ``init_needed()`` is called. dummy = get_needed() with pytest.raises(NotImplementedError): dummy.clear() with pytest.raises(NotImplementedError): clear_needed() # Initialize a needed resources object. needed = init_needed() assert get_needed() == needed assert thread_local_needed_data.__dict__[NEEDED] == needed # Clear it. del_needed() # It is gone, really. with pytest.raises(KeyError): thread_local_needed_data.__dict__[NEEDED] # Clearing it again is OK. del_needed() # get_needed still work, dummy-style. dummy2 = get_needed() assert dummy2 != needed with pytest.raises(NotImplementedError): dummy.clear() with pytest.raises(NotImplementedError): clear_needed()
def print_success(self, appstruct): response = {} response['agenda_items'] = self.get_agenda_items(appstruct['agenda_items']) response['proposal_state_titles'] = dict(proposal_states(self.request)) self.include_discussion_userids = appstruct['include_discussion_userids'] self.no_userid = response['no_userid'] = appstruct['no_userid'] output = self.export_xml(response, appstruct) # Kill all output from fanstatic clear_needed() return Response(output, content_type='text/xml')
def test_convenience_clear(): foo = Library('foo', '') x1 = Resource(foo, 'a.js') x2 = Resource(foo, 'b.css') y1 = Resource(foo, 'c.js', depends=[x1, x2]) z1 = Resource(foo, 'd.js') z2 = Resource(foo, 'e.js', depends=[z1, x1]) needed = init_needed(resources=[y1]) assert sort_resources(needed.resources()) == [x2, x1, y1] # For some reason,for example an error page needs to be rendered, # the currently needed resources need to be cleared. clear_needed() assert len(needed.resources()) == 0 z2.need() assert sort_resources(needed.resources()) == [x1, z1, z2]
def __call__(self, environ, start_response): try: return self.app(environ, start_response) except Exception: fanstatic.clear_needed() raise
def tearDown(self): testing.tearDown() clear_needed()