Here are the examples of the python api scrapy.commands.genspider.sanitize_module_name taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
Source : recorder.py
with BSD 3-Clause "New" or "Revised" License
from scrapinghub
with BSD 3-Clause "New" or "Revised" License
from scrapinghub
def __init__(self, spider):
self.spider = spider
self.settings = spider.settings
self.spider_name = sanitize_module_name(spider.name)
self.spider_init_attrs = self.spider_attrs()
self.fixture_counters = {}
self._set_max_fixtures()
self.base_path = get_base_path(self.settings)
self._create_dir(self.base_path, exist_ok=True)
self._clear_fixtures()
@classmethod
0
Source : cli.py
with BSD 3-Clause "New" or "Revised" License
from scrapinghub
with BSD 3-Clause "New" or "Revised" License
from scrapinghub
def __init__(self, parser):
self.parser = parser
self.args = parser.parse_args()
if not inside_project():
self._error("No active Scrapy project")
self.command = self.args.command
self.spider = self.args.spider
self.callback = self.args.callback
self.fixture = self.args.fixture
self.project_dir = get_project_dir()
sys.path.append(self.project_dir)
self.settings = get_project_settings()
base_path = get_base_path(self.settings)
self.tests_dir = os.path.join(base_path, 'tests')
if self.spider:
self.spider = sanitize_module_name(self.spider)
self.callbacks_dir = self._get_callbacks_dir(self.spider)
if not os.path.isdir(self.callbacks_dir):
self._error("No recorded data found for spider '{}'".format(self.spider))
if self.callback:
self.callback_dir = os.path.join(self.callbacks_dir, self.callback)
if not os.path.isdir(self.callback_dir):
self._error(
"No recorded data found for callback "
"'{}' from '{}' spider".format(self.callback, self.spider))
if self.fixture:
self.fixture_path = os.path.join(self.callback_dir, self.parse_fixture_arg())
if not os.path.isfile(self.fixture_path):
self._error("Fixture '{}' not found".format(self.fixture_path))
def _error(self, msg):
0
Source : cli.py
with BSD 3-Clause "New" or "Revised" License
from scrapinghub
with BSD 3-Clause "New" or "Revised" License
from scrapinghub
def _update_legacy_test(self, path, cassette):
path_dir = os.path.dirname(path)
older_version_test = os.path.join(path_dir, 'test_fixture1.py')
if os.path.isfile(older_version_test):
to_remove = os.path.join(path_dir, 'test_fixture*.py')
for test in glob(to_remove):
if test == older_version_test:
os.rename(test, path)
continue
os.remove(test)
test_name = (
sanitize_module_name(cassette.spider_name) + '__' +
cassette.request['callback']
)
with open(path, 'r+') as f:
old = f.read()
command = 'Scrapy Autounit'
command_re = re.search('# Generated by: (.*) # noqa', old)
if command_re:
command = command_re.group(1)
test_code = TEST_TEMPLATE.format(test_name=test_name, command=command)
f.seek(0)
f.write(test_code)
f.truncate()
def parse_fixture_arg(self):