def test_local_template_dir(self): with tempdir.TemporaryWorkingDirectory() as td: with patch('os.getcwd', return_value=os.path.abspath(td)): template = 'mytemplate' template_file = os.path.join(template, 'index.py.j2') template_abs = os.path.abspath(os.path.join(td, template_file)) template_conf = os.path.abspath( os.path.join(td, template, 'conf.json')) os.mkdir(os.path.dirname(template_abs)) test_output = 'local!' with open(template_abs, 'w') as f: f.write(test_output) with open(template_conf, 'w') as f: # Mimic having a superset of accepted mimetypes f.write( json.dumps( Config(mimetypes={ "text/x-python": True, "text/html": True, }))) config = Config() config.TemplateExporter.template_name = template exporter = self._make_exporter(config=config) assert os.path.abspath( exporter.template.filename) == template_abs assert exporter.template_name == template assert os.path.join(td, template) in exporter.template_paths
def test_relative_template_file(self): with tempdir.TemporaryWorkingDirectory() as td: os.mkdir('relative') template = os.path.abspath( os.path.join(td, 'relative', 'relative_template.tpl')) test_output = 'relative!' with open(template, 'w') as f: f.write(test_output) config = Config() config.TemplateExporter.template_file = template exporter = self._make_exporter(config=config) assert os.path.abspath(exporter.template.filename) == template assert os.path.dirname(template) in [ os.path.abspath(d) for d in exporter.template_path ]
def test_relative_template_file(self): with tempdir.TemporaryWorkingDirectory() as td: with patch('os.getcwd', return_value=os.path.abspath(td)): template = os.path.join('relative', 'relative_template.ext.j2') template_abs = os.path.abspath(os.path.join(td, template)) os.mkdir(os.path.dirname(template_abs)) test_output = 'relative!' with open(template_abs, 'w') as f: f.write(test_output) config = Config() config.TemplateExporter.template_file = template exporter = self._make_exporter(config=config) assert os.path.abspath( exporter.template.filename) == template_abs assert os.path.dirname(template_abs) in [ os.path.abspath(d) for d in exporter.template_paths ]
def test_relative_template_name_tpl_compatibility(self): with tempdir.TemporaryWorkingDirectory() as td: with patch('os.getcwd', return_value=os.path.abspath(td)): template = os.path.join('relative', 'relative_template.tpl') template_abs = os.path.abspath(os.path.join(td, template)) os.mkdir(os.path.dirname(template_abs)) test_output = 'relative!' with open(template_abs, 'w') as f: f.write(test_output) config = Config() # We're setting the template_name instead of the template_file config.TemplateExporter.template_name = template with pytest.warns(DeprecationWarning): exporter = self._make_exporter(config=config) assert os.path.abspath( exporter.template.filename) == template_abs assert os.path.dirname(template_abs) in [ os.path.abspath(d) for d in exporter.template_paths ]