<s> import os <EOL> from datetime import datetime <EOL> from twisted . trial import unittest <EOL> from scrapy . extensions . spiderstate import SpiderState <EOL> from scrapy . spiders import Spider <EOL> from scrapy . exceptions import NotConfigured <EOL> from scrapy . utils . test import get_crawler <EOL> class SpiderStateTest ( unittest . TestCase ) : <EOL> def test_store_load ( self ) : <EOL> jobdir = self . mktemp ( ) <EOL> os . mkdir ( jobdir ) <EOL> spider = Spider ( name = '<STR_LIT:default>' ) <EOL> dt = datetime . now ( ) <EOL> ss = SpiderState ( jobdir ) <EOL> ss . spider_opened ( spider ) <EOL> spider . state [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> spider . state [ '<STR_LIT>' ] = dt <EOL> ss . spider_closed ( spider ) <EOL> spider2 = Spider ( name = '<STR_LIT:default>' ) <EOL> ss2 = SpiderState ( jobdir ) <EOL> ss2 . spider_opened ( spider2 ) <EOL> self . assertEqual ( spider . state , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : dt } ) <EOL> ss2 . spider_closed ( spider2 ) <EOL> def test_state_attribute ( self ) : <EOL> spider = Spider ( name = '<STR_LIT:default>' ) <EOL> ss = SpiderState ( ) <EOL> ss . spider_opened ( spider ) <EOL> self . assertEqual ( spider . state , { } ) <EOL> ss . spider_closed ( spider ) <EOL> def test_not_configured ( self ) : <EOL> crawler = get_crawler ( Spider ) <EOL> self . assertRaises ( NotConfigured , SpiderState . from_crawler , crawler ) </s>
