def test_create_outputfile_included(mock_run, mock_module1rst, mock_search_for_robotdocsconf): mock_run.side_effect = [RunResult(robotdoc_generation_call, 0), runresult_robotlib_kwd_list_2kwds, RunResult(sphinxdocs_generation_call, 0)] mock_search_for_robotdocsconf.return_value = ['folder2'] DocCreator(robotdocs_root_folders='robotdocs', run=mock_run).create() assert mock_module1rst.content == robotdocs_rst_expected_content()
def test_create_generate_robotdocs_rst_synopsis(mock_run, mock_robotdocsrst, mock_search_for_robotdocsconf): mock_search_for_robotdocsconf.return_value = ['folder1'] mock_run.side_effect = [ RunResult(robotdoc_generation_call, 0), runresult_robotlib_kwd_list_2kwds, RunResult(sphinxdocs_generation_call, 0) ] DocCreator(robotdocs_root_folders='robotdocs', run=mock_run).create() assert mock_robotdocsrst.content == robotdocs_rst_expected_content( library_sections=[robotdocs_rst_library_section(synopsis='synopsis')])
def test_create_one_robotdocsconf(mock_run, mock_robotdocsrst, mock_search_for_robotdocsconf): mock_run.side_effect = [RunResult(robotdoc_generation_call, 0), runresult_robotlib_kwd_list_2kwds, RunResult(sphinxdocs_generation_call, 0)] mock_search_for_robotdocsconf.return_value = ['folder1'] DocCreator(robotdocs_root_folders='robotdocs', run=mock_run).create() assert mock_robotdocsrst.content == robotdocs_rst_expected_content() assert mock_run.mock_calls[0] == mock.call(robotdoc_generation_call) assert mock_run.mock_calls[1] == mock.call(robotdoc_kwd_list_call) assert mock_run.mock_calls[2] == mock.call(sphinxdocs_generation_call)
def test_create_multiargs(mock_run, mock_search_for_robotdocsconf): mock_run.side_effect = [ RunResult(robotdoc_generation_call, 0), runresult_robotlib_kwd_list_2kwds, RunResult(sphinxdocs_generation_call, 0) ] mock_search_for_robotdocsconf.return_value = ['folder1'] DocCreator(robotdocs_root_folders='folder1', run=mock_run).create() assert (mock_run.mock_calls[0] == mock.call( 'python' ' -m robot.libdoc' ' -f html' ' -F docformat' ' library::arg1::arg2' ' {}'.format(os.path.join('robotdocs', 'library.html'))))
def test_create_no_sphinxdocs(mock_run, mock_search_for_robotdocsconf): mock_run.side_effect = [RunResult(robotdoc_generation_call, 0)] mock_search_for_robotdocsconf.return_value = ['folder1'] DocCreator(robotdocs_root_folders='robotdocs', run=mock_run).create() mock_run.assert_called_once_with(robotdoc_generation_call)
def test_create_robotdocs(mock_run, mock_robotdocsrst, mock_search_for_robotdocsconf, runresult): mock_run.side_effect = [RunResult(robotdoc_generation_call, 0), runresult] mock_search_for_robotdocsconf.return_value = ['folder1'] dc = DocCreator(robotdocs_root_folders='robotdocs', run=mock_run) dc.create_robotdocs() assert mock_run.mock_calls[0] == mock.call(robotdoc_generation_call) assert mock_run.mock_calls[1] == mock.call(robotdoc_kwd_list_call) assert mock_robotdocsrst.content == robotdocs_rst_expected_content()
def test_create_with_robotdocs_but_no_html_extra_path( mock_run, mock_search_for_robotdocsconf): mock_run.side_effect = [RunResult(robotdoc_generation_call, 0), runresult_robotlib_kwd_list_2kwds] mock_search_for_robotdocsconf.return_value = ['folder1'] with pytest.raises(FailedToCreateDocs) as excinfo: DocCreator(robotdocs_root_folders='robotdocs', run=mock_run).create() message = "Incorrect configuration found in {sphinx_conf}" message = message.format(sphinx_conf=os.path.join('sphinxdocs', 'conf.py')) assert message in str(excinfo.value)
def test_create_from_resource_file(mock_run, mock_robotdocsrst, mock_search_for_robotdocsconf): mock_run.side_effect = [RunResult(robotdoc_generation_call, 0), runresult_robotlib_kwd_list_2kwds, RunResult(sphinxdocs_generation_call, 0)] mock_search_for_robotdocsconf.return_value = ['folder1'] DocCreator(robotdocs_root_folders='folder1', run=mock_run).create() assert (mock_run.mock_calls[0] == mock.call('python' ' -m robot.libdoc' ' -f html' ' -F robot' ' resources/subfolder1/subfolder2/resource_file.robot' ' {}'.format( os.path.join('robotdocs', 'resource_file.robot.html')))) assert (mock_robotdocsrst.content == robotdocs_rst_expected_content( library_sections=[robotdocs_rst_library_section( libname='resources/subfolder1/subfolder2/resource_file.robot')]))
def test_create_without_robotdocs(mock_run): mock_run.side_effect = [RunResult(sphinxdocs_generation_call, 0)] DocCreator(robotdocs_root_folders='robotdocs', run=mock_run).create() mock_run.assert_called_with(sphinxdocs_generation_call)
return mfile @pytest.fixture(scope='function') def mock_module2rst(request): mfile = MockFile(filename=os.path.join('sphinxdocs', 'module2.rst')) create_patch(mfile, request) return mfile @pytest.fixture(scope='function') def mock_run(): return mock.Mock() runresult_robotlib_kwd_list_nokwds = RunResult( 'python -m robot.libdoc library list', 0, stdout='') runresult_robotlib_kwd_list_2kwds = RunResult( 'python -m robot.libdoc library list', 0, stdout='Keyword One{linesep}Keyword Two{linesep}'.format( linesep=os.linesep)) runresult_robotlib_kwd_list_2kwds_as_binary = RunResult( 'python -m robot.libdoc library list', 0, stdout='Keyword One{linesep}Keyword Two{linesep}'.format( linesep=os.linesep).encode('ascii')) class MockIsdir(object):