Пример #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')