def test_plugin_glob_with_one_parameter(self): tmp_dir = tempfile.mkdtemp() plugins = ['glob'] expected_result = pypelinin.process(plugins, [tmp_dir]) try: self.assertEquals(expected_result, [tmp_dir]) finally: shutil.rmtree(tmp_dir)
def test_plugin_glob_with_two_parameters_without_asterisk_should_return_a_list_with_those_parameters(self): tmp_dir_1 = tempfile.mkdtemp() tmp_dir_2 = tempfile.mkdtemp() plugins = ['glob'] expected_result = pypelinin.process(plugins, [tmp_dir_1, tmp_dir_2]) try: self.assertEquals(len(expected_result), 2) self.assertItemsEqual(expected_result, [tmp_dir_1, tmp_dir_2]) finally: shutil.rmtree(tmp_dir_1) shutil.rmtree(tmp_dir_2)
def test_simple(self): tmp_fd = tempfile.NamedTemporaryFile(delete=False) tmp_fd.write('testing\n=======') tmp_fd.close() plugins = ['markdown'] result_filenames = pypelinin.process(plugins, [tmp_fd.name]) expected_output = '<h1>testing</h1>' out_fd = open(result_filenames[0]) self.assertEquals(out_fd.read(), expected_output) out_fd.close() os.remove(result_filenames[0]) os.remove(tmp_fd.name)
def test_simple_pipe_with_2_plugins(self): tmp_fd = tempfile.NamedTemporaryFile(delete=False) random_chars = [chr(int(97 + random.random() * 26)) for x in range(20)] random_string = ''.join(random_chars) tmp_fd.write('%s\n%s' % (random_string, '=' * len(random_string))) tmp_fd.close() tmp_filename = tmp_fd.name plugins = ['glob', 'markdown'] result_filenames = pypelinin.process(plugins, [tmp_filename]) expected_output_filename = tmp_filename + '.html' self.assertEquals(result_filenames[0], expected_output_filename) self.assertTrue(os.path.exists(expected_output_filename)) expected_output = '<h1>%s</h1>' % random_string out_fd = open(result_filenames[0]) self.assertEquals(out_fd.read(), expected_output) out_fd.close() os.remove(result_filenames[0]) os.remove(tmp_fd.name)
def test_more_than_one_file(self): tmp_fd_1 = tempfile.NamedTemporaryFile(delete=False) tmp_fd_1.write('testing 1\n=========') tmp_fd_1.close() tmp_fd_2 = tempfile.NamedTemporaryFile(delete=False) tmp_fd_2.write('testing 2\n=========') tmp_fd_2.close() plugins = ['markdown'] expected_filenames = [tmp_fd_1.name, tmp_fd_2.name] result_filenames = pypelinin.process(plugins, expected_filenames) out_fd_1 = open(result_filenames[0]) out_fd_2 = open(result_filenames[1]) self.assertEquals(out_fd_1.read(), '<h1>testing 1</h1>') self.assertEquals(out_fd_2.read(), '<h1>testing 2</h1>') out_fd_1.close() out_fd_2.close() os.remove(tmp_fd_1.name) os.remove(tmp_fd_2.name) os.remove(result_filenames[0]) os.remove(result_filenames[1])
def test_when_output_is_not_list_should_raise_TypeError(self): result = pypelinin.process(['glob'], ['some string']) self.assertEquals(type(result), type([]))
def test_when_input_is_not_list_should_raise_TypeError(self): with self.assertRaises(TypeError): result = pypelinin.process(['glob'], 'some string')
def test_when_plugin_list_is_empty_ValueError_should_be_raised(self): with self.assertRaises(ValueError): result = pypelinin.process([], ['some string'])
def test_invalid_plugin_should_raise_InvalidPluginException(self): with self.assertRaises(pypelinin.InvalidPluginException): pypelinin.process(['this_plugin_does_not_exist'])
#!/usr/bin/env python import os import pypelinin plugins = ['glob', 'markdown'] parameters = [os.getcwd() + os.path.sep + '*.markdown'] pypelinin.process(plugins, parameters)