예제 #1
0
 def test_spidername_time(self):
     formatted = _format("Spider: $spider:name. Item scraped at $time",
                         self.spider, self.response, self.item, {})
     self.assertRegexpMatches(
         formatted,
         'Spider: myspider. Item scraped at \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$'
     )
예제 #2
0
 def test_response(self):
     formatted = _format("$response:url", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, self.response.url)
예제 #3
0
 def test_invalidattr(self):
     formatted = _format("Argument arg2: $spider:arg2", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "Argument arg2: $spider:arg2")
예제 #4
0
 def test_noargs(self):
     """If entity does not accept arguments, don't substitute"""
     formatted = _format("Scraped on day $unixtime:arg", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "Scraped on day $unixtime:arg")
예제 #5
0
 def test_settings(self):
     formatted = _format("$setting:MY_SETTING", self.spider, self.response, self.item, {"$setting": {"MY_SETTING": True}})
     self.assertEqual(formatted, 'True')
예제 #6
0
 def test_spiderarg(self):
     formatted = _format("Argument arg1: $spider:arg1", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, 'Argument arg1: val1')
예제 #7
0
 def test_isotime(self):
     formatted = _format("$isotime", self.spider, self.response, self.item, {})
     self.assertRegexpMatches(formatted, '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}$')
예제 #8
0
 def test_spidername_time(self):
     formatted = _format("Spider: $spider:name. Item scraped at $time", self.spider, self.response, self.item, {})
     self.assertRegexpMatches(formatted, 'Spider: myspider. Item scraped at \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$')
예제 #9
0
 def test_spiderattr(self):
     formatted = _format("$spider:start_urls", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "['http://example.com']")
예제 #10
0
 def test_spiderarg(self):
     formatted = _format("Argument arg1: $spider:arg1", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, 'Argument arg1: val1')
예제 #11
0
 def test_jobid(self):
     os.environ["SCRAPY_JOB"] = 'aa788'
     formatted = _format("job id '$jobid' for spider $spider:name", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "job id 'aa788' for spider myspider")
예제 #12
0
 def test_isotime(self):
     formatted = _format("$isotime", self.spider, self.response, self.item, {})
     self.assertRegexpMatches(formatted, '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}$')
예제 #13
0
 def test_unixtime(self):
     formatted = _format("Item scraped at $unixtime", self.spider, self.response, self.item, {})
     self.assertRegexpMatches(formatted, 'Item scraped at \d+\.\d+$')
예제 #14
0
 def test_hello(self):
     self.assertEqual(_format("hello world!", self.spider, self.response, self.item, {}), 'hello world!')
예제 #15
0
 def test_regex(self):
     formatted = _format("$field:url,r'item_no=(\d+)'", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, '345')
예제 #16
0
 def test_fields_copy(self):
     formatted = _format("$field:nom", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, 'myitem')
예제 #17
0
 def test_hello(self):
     self.assertEqual(_format("hello world!", self.spider, self.response, self.item, {}), 'hello world!')
예제 #18
0
 def test_settings(self):
     formatted = _format("$setting:MY_SETTING", self.spider, self.response, self.item, {"$setting": {"MY_SETTING": True}})
     self.assertEqual(formatted, 'True')
예제 #19
0
 def test_unixtime(self):
     formatted = _format("Item scraped at $unixtime", self.spider, self.response, self.item, {})
     self.assertRegexpMatches(formatted, 'Item scraped at \d+\.\d+$')
예제 #20
0
 def test_notexisting(self):
     """Not existing entities are not substituted"""
     formatted = _format("Item scraped at $myentity", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, 'Item scraped at $myentity')
예제 #21
0
 def test_jobid(self):
     os.environ["SCRAPY_JOB"] = 'aa788'
     formatted = _format("job id '$jobid' for spider $spider:name", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "job id 'aa788' for spider myspider")
예제 #22
0
 def test_noargs(self):
     """If entity does not accept arguments, don't substitute"""
     formatted = _format("Scraped on day $unixtime:arg", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "Scraped on day $unixtime:arg")
예제 #23
0
 def test_spiderattr(self):
     formatted = _format("$spider:start_urls", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "['http://example.com']")
예제 #24
0
 def test_noargs2(self):
     """If entity does not have enough arguments, don't substitute"""
     formatted = _format("$spider", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "$spider")
예제 #25
0
 def test_notexisting(self):
     """Not existing entities are not substituted"""
     formatted = _format("Item scraped at $myentity", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, 'Item scraped at $myentity')
예제 #26
0
 def test_invalidattr(self):
     formatted = _format("Argument arg2: $spider:arg2", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "Argument arg2: $spider:arg2")
예제 #27
0
 def test_noargs2(self):
     """If entity does not have enough arguments, don't substitute"""
     formatted = _format("$spider", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "$spider")
예제 #28
0
 def test_environment(self):
     os.environ["TEST_ENV"] = "testval"
     formatted = _format("$env:TEST_ENV", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "testval")
예제 #29
0
 def test_environment(self):
     os.environ["TEST_ENV"] = "testval"
     formatted = _format("$env:TEST_ENV", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, "testval")
예제 #30
0
 def test_response(self):
     formatted = _format("$response:url", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, self.response.url)
예제 #31
0
 def test_fields_copy(self):
     formatted = _format("$field:nom", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, 'myitem')
예제 #32
0
 def test_regex(self):
     formatted = _format("$field:url,r'item_no=(\d+)'", self.spider, self.response, self.item, {})
     self.assertEqual(formatted, '345')