<s> """<STR_LIT>""" <EOL> import inspect <EOL> from unittest import TestCase <EOL> from scrapy import signals , Field , Item <EOL> from mock import patch , mock_open , Mock , call <EOL> from arachne . pipelines import ExportCSV , ExportData , ExportJSON <EOL> from scrapy . contrib . exporter import CsvItemExporter , JsonItemExporter <EOL> class ScrapyItem ( Item ) : <EOL> field1 = Field ( ) <EOL> field2 = Field ( ) <EOL> field3 = Field ( ) <EOL> class TestPipelines ( TestCase ) : <EOL> def test_cls_export_data ( self ) : <EOL> cls = ExportData ( ) <EOL> self . assertTrue ( inspect . ismethod ( cls . from_crawler ) ) <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> cls . spider_opened ( '<STR_LIT:test>' ) <EOL> crawler_mock = Mock ( ) <EOL> cls . from_crawler ( crawler_mock ) <EOL> assert crawler_mock . signals . connect . called <EOL> self . assertEquals ( cls . files , { } ) <EOL> self . assertIsNone ( cls . exporter ) <EOL> def test_export_cls ( self ) : <EOL> test_classes = [ <EOL> { '<STR_LIT>' : ExportJSON , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : JsonItemExporter } , <EOL> { '<STR_LIT>' : ExportCSV , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : CsvItemExporter } <EOL> ] <EOL> for test_cls in test_classes : <EOL> cls = test_cls [ '<STR_LIT>' ] ( ) <EOL> mock_open_func = mock_open ( read_data = '<STR_LIT>' ) <EOL> spider = Mock ( ) <EOL> spider . name = '<STR_LIT:abc>' <EOL> with patch ( '<STR_LIT>' , mock_open_func ) : <EOL> cls . spider_opened ( spider ) <EOL> path = '<STR_LIT>' % ( test_cls [ '<STR_LIT>' ] , <EOL> test_cls [ '<STR_LIT>' ] ) <EOL> mock_open_func . assert_called_with ( path , '<STR_LIT>' ) <EOL> self . assertIsInstance ( cls . exporter , test_cls [ '<STR_LIT>' ] ) <EOL> cls . spider_closed ( spider ) <EOL> self . assertEquals ( cls . files , { } ) <EOL> item = ScrapyItem ( ) <EOL> result = cls . process_item ( item , spider ) <EOL> self . assertEquals ( item , result ) </s>
