def test_process_invalid_ext(self): # we require a valid filename extension for source path proc = PSJHTMLProcessor() path, metadata = proc.process( '/some/filepath/with/invalid_ext.ext', "Fake-Metadata") assert path == '/some/filepath/with/invalid_ext.ext' assert metadata == "Fake-Metadata"
def test_process(self): # we can process docs. The result will be a doc with a <div> tag # accompanied by a CSS file called ``psj.css``. self.create_source() orig_path = self.result_path proc = PSJHTMLProcessor() self.result_path, metadata = proc.process( orig_path, {'error': False, 'error-descr': ''}) assert metadata == {'error': False, 'error-descr': ''} assert not os.path.exists(orig_path) assert self.result_path != orig_path assert open(self.result_path, 'r').read().startswith('<div') dirlist = os.listdir(os.path.dirname(self.result_path)) self.assertEqual(sorted(dirlist), ['psj.css', 'sample.html'])
def test_proc_always_generates_css(self): # make sure we alway get a CSS file called 'psj.css', # even if no CSS was put in. proc = PSJHTMLProcessor() dir_path = tempfile.mkdtemp() html_path = os.path.join(dir_path, 'sample.html') with open(html_path, 'wb') as fd: fd.write('<html><body><h1>Foo</h1></body></html>') self.result_path, metadata = proc.process( html_path, {'error': False, 'error-descr': ''}) result_dir = os.path.dirname(self.result_path) assert sorted(os.listdir(result_dir)) == ['psj.css', 'sample.html'] with open(os.path.join(result_dir, 'psj.css'), 'rb') as fd: css = fd.read() assert css == ''