Esempio n. 1
0
def mock_requirements_log_file_raises_tmpdir(request, tmpdir):
    with tmpdir.as_cwd():

        mfile = MockFile(filename=Runner().requirements_log_file,
                         content="reguirements install log")

        def exception(*args, **kwargs):
            raise Exception('message')

        mfile.set_side_effect(exception)
        create_patch(mfile, request)
        return tmpdir
Esempio n. 2
0
def test_set_saver():
    mfile = MockFile(filename='filename')

    def saver(content):
        mfile.set_content(content + 'more_content')

    mfile.set_saver(saver)
    with mfile:
        with open('filename', 'w') as f:
            f.write('content')
        with open('filename') as f:
            assert f.read() == 'contentmore_content'
Esempio n. 3
0
def test_mockfile():
    with MockFile(filename='filename', content='content'):
        with open('filename', 'a') as f:
            f.write('more_content')
        with open('filename') as f:
            assert f.read() == 'contentmore_content'
    assert not os.path.isfile('filename')
def mock_robotdocsconf(request):
    filename = os.path.join('folder1', 'robotdocsconf.py')
    mfile = MockFile(filename=filename,
                     content="robotdocs={\n"
                     "    'library':\n"
                     "        {'args': ['arg'], 'docformat': 'docformat'}}")
    create_patch(mfile, request)
    return mfile
def mock_sphinxdocsconf(request):
    filename = os.path.join('sphinxdocs', 'conf.py')
    template = "html_static_path = ['_static']\n" \
               "html_extra_path = ['{path}']\n"
    content = template.format(path=os.path.join(os.pardir, 'robotdocs'))
    mfile = MockFile(filename=filename, content=content)
    create_patch(mfile, request)
    return mfile
Esempio n. 6
0
def test_mockfile_sideeffect():
    def raise_io_error():
        raise IOError('message')

    with pytest.raises(IOError) as excinfo:
        with MockFile(filename='filename',
                      side_effect=lambda *args: raise_io_error()):
            open('filename')

    assert excinfo.value.args[0] == 'message'
def mock_robotdocsconf_with_modulename(request):
    filename = os.path.join('folder3', 'robotdocsconf.py')
    mfile = MockFile(filename=filename,
                     content="module_name=\"module libraries\"\n\n"
                     "robotdocs={\n"
                     "    'library':\n"
                     "        {'args': ['arg1', 'arg2'],"
                     " 'docformat': 'docformat'}}")
    create_patch(mfile, request)
    return mfile
Esempio n. 8
0
def test_set_sideeffect():
    mfile = MockFile()
    mfile.set_side_effect('side_effect')
    assert mfile.side_effect == 'side_effect'
Esempio n. 9
0
def test_set_content():
    mfile = MockFile()
    mfile.set_content('content')
    assert mfile.content == 'content'
Esempio n. 10
0
def test_set_filename():
    mfile = MockFile()
    mfile.set_filename('filename')
    assert mfile.filename == 'filename'
Esempio n. 11
0
def test_mockfile_saver():
    mfile = MockFile()
    assert mfile.saver == mfile.set_content
def mock_module2rst(request):
    mfile = MockFile(filename=os.path.join('sphinxdocs', 'module2.rst'))
    create_patch(mfile, request)
    return mfile
def mock_robotdocsrst(request):
    mfile = MockFile(filename=os.path.join('sphinxdocs', 'robotdocs.rst'))
    create_patch(mfile, request)
    return mfile
Esempio n. 14
0
def mock_pydistutilscfg(request):
    mfile = MockFile(filename=Runner().pydistutilscfg)
    create_patch(mfile, request)
    return mfile