<s> import unittest <EOL> from scrapy . spiders import Spider <EOL> from scrapy . statscollectors import StatsCollector , DummyStatsCollector <EOL> from scrapy . utils . test import get_crawler <EOL> class StatsCollectorTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . crawler = get_crawler ( Spider ) <EOL> self . spider = self . crawler . _create_spider ( '<STR_LIT:foo>' ) <EOL> def test_collector ( self ) : <EOL> stats = StatsCollector ( self . crawler ) <EOL> self . assertEqual ( stats . get_stats ( ) , { } ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' , '<STR_LIT:default>' ) , '<STR_LIT:default>' ) <EOL> stats . set_value ( '<STR_LIT:test>' , '<STR_LIT:value>' ) <EOL> self . assertEqual ( stats . get_stats ( ) , { '<STR_LIT:test>' : '<STR_LIT:value>' } ) <EOL> stats . set_value ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( stats . get_stats ( ) , { '<STR_LIT:test>' : '<STR_LIT:value>' , '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> stats . inc_value ( '<STR_LIT>' ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> stats . inc_value ( '<STR_LIT>' , <NUM_LIT:6> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT:30> ) <EOL> stats . max_value ( '<STR_LIT>' , <NUM_LIT:6> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT:30> ) <EOL> stats . max_value ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> stats . max_value ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> stats . min_value ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> stats . min_value ( '<STR_LIT>' , <NUM_LIT> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> stats . min_value ( '<STR_LIT>' , <NUM_LIT:7> ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , <NUM_LIT:7> ) <EOL> def test_dummy_collector ( self ) : <EOL> stats = DummyStatsCollector ( self . crawler ) <EOL> self . assertEqual ( stats . get_stats ( ) , { } ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( stats . get_value ( '<STR_LIT>' , '<STR_LIT:default>' ) , '<STR_LIT:default>' ) <EOL> stats . set_value ( '<STR_LIT:test>' , '<STR_LIT:value>' ) <EOL> stats . inc_value ( '<STR_LIT>' ) <EOL> stats . max_value ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> stats . min_value ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> stats . open_spider ( '<STR_LIT:a>' ) <EOL> stats . set_value ( '<STR_LIT:test>' , '<STR_LIT:value>' , spider = self . spider ) <EOL> self . assertEqual ( stats . get_stats ( ) , { } ) <EOL> self . assertEqual ( stats . get_stats ( '<STR_LIT:a>' ) , { } ) </s>
