<s> import os <EOL> from django . conf import settings <EOL> if not settings . configured : <EOL> settings . configure ( <EOL> INSTALLED_APPS = ( ) , <EOL> DATABASES = { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> TEMPLATE_DIRS = ( <EOL> os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) , <EOL> ) <EOL> ) <EOL> import json <EOL> import tempfile <EOL> import unittest <EOL> from cStringIO import StringIO <EOL> from nose . plugins import PluginTester <EOL> from django . template . loader import get_template <EOL> from templateusage import TemplateUsageReportPlugin <EOL> class TemplateUsageReportTestMixin ( PluginTester ) : <EOL> TEMPLATE_NAME = '<STR_LIT>' <EOL> activate = '<STR_LIT>' <EOL> plugins = [ TemplateUsageReportPlugin ( ) ] <EOL> def makeSuite ( self ) : <EOL> class TestCase ( unittest . TestCase ) : <EOL> def runTest ( _self ) : <EOL> get_template ( self . TEMPLATE_NAME ) <EOL> return unittest . TestSuite ( [ TestCase ( ) ] ) <EOL> class TemplateUsageReportPluginTestCase ( TemplateUsageReportTestMixin , unittest . TestCase ) : <EOL> def test_basic ( self ) : <EOL> self . assertIn ( self . TEMPLATE_NAME , self . plugins [ <NUM_LIT:0> ] . used_templates ) <EOL> def test_included ( self ) : <EOL> self . assertIn ( '<STR_LIT>' , self . plugins [ <NUM_LIT:0> ] . used_templates ) <EOL> def test_unused ( self ) : <EOL> self . assertIn ( '<STR_LIT>' , self . plugins [ <NUM_LIT:0> ] . unused_templates ) <EOL> class IgnoredDirectoryUsageReportPluginTestCase ( TemplateUsageReportTestMixin , unittest . TestCase ) : <EOL> args = ( '<STR_LIT>' , ) <EOL> def test_ignored ( self ) : <EOL> self . assertNotIn ( '<STR_LIT>' , self . plugins [ <NUM_LIT:0> ] . used_templates ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . plugins [ <NUM_LIT:0> ] . unused_templates ) <EOL> class ReportFileTestCase ( TemplateUsageReportTestMixin , unittest . TestCase ) : <EOL> def setUp ( self , * args , ** kwargs ) : <EOL> f = tempfile . NamedTemporaryFile ( delete = False ) <EOL> f . close ( ) <EOL> self . filename = f . name <EOL> self . args = ( '<STR_LIT>' % self . filename , ) <EOL> super ( ReportFileTestCase , self ) . setUp ( * args , ** kwargs ) <EOL> def tearDown ( self ) : <EOL> os . unlink ( self . filename ) <EOL> def test_report_file ( self ) : <EOL> self . assertIsNotNone ( self . plugins [ <NUM_LIT:0> ] . outfile ) <EOL> with open ( self . filename ) as raw : <EOL> report = json . load ( raw ) <EOL> used = set ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( used , set ( report [ '<STR_LIT>' ] ) ) <EOL> unused = set ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( unused , set ( report [ '<STR_LIT>' ] ) ) </s>
