<commit_before>import py

here = py.magic.autopath().dirpath()
update_website = here.join('../../bin/_update_website.py').pyimport()

def test_rsync():
    temp = py.test.ensuretemp('update_website_rsync')
    pkgpath = temp.join('pkg')
    apipath = temp.join('apigen')
    pkgpath.ensure('foo/bar.txt', file=True).write('baz')
    pkgpath.ensure('spam/eggs.txt', file=True).write('spam')
    apipath.ensure('api/foo.html', file=True).write('<html />')
    apipath.ensure('source/spam.html', file=True).write('<html />')

    rsyncpath = temp.join('rsync')
    assert not rsyncpath.check()
    gateway = py.execnet.PopenGateway()
    update_website.rsync(pkgpath, apipath, gateway, rsyncpath.strpath)
    assert rsyncpath.check(dir=True)
    assert rsyncpath.join('pkg').check(dir=True)
    assert rsyncpath.join('pkg/spam/eggs.txt').read() == 'spam'
    assert rsyncpath.join('apigen').check(dir=True)
    assert rsyncpath.join('apigen/api/foo.html').read() == '<html />'

def setup_pkg(testname):
    temp = py.test.ensuretemp(testname)
    pkgpath = temp.ensure('pkg', dir=True)
    pyfile = pkgpath.ensure('mod.py').write(py.code.Source("""
        def foo(x):
            return x + 1
    """))
    testfile = pkgpath.ensure('test/test_mod.py').write(py.code.Source("""
        from pkg.sub import foo
        def test_foo():
            assert foo(1) == 2
    """))
    initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""\
        import py
        from py.__.initpkg import initpkg
        initpkg(__name__, exportdefs={
            'sub.foo': ('./mod.py', 'foo'),
        })
    """))
    return pkgpath

def test_run_tests():
    if py.std.sys.platform == "win32":
        py.test.skip("update_website is not supposed to be run from win32")
    pkgpath = setup_pkg('update_website_run_tests')
    errors = update_website.run_tests(pkgpath)
    assert not errors
    assert pkgpath.join('../apigen').check(dir=True)
    assert pkgpath.join('../apigen/api/sub.foo.html').check(file=True)

def test_run_tests_failure():
    pkgpath = setup_pkg('update_website_run_tests_failure')
    assert not pkgpath.join('../apigen').check(dir=True)
    pkgpath.ensure('../apigen', file=True)
    errors = update_website.run_tests(pkgpath)
    assert errors # some error message
<commit_msg>[svn r38143] Removed some confusing output to stdout/stderr (output of failing tests, which are part of a test that tests whether a set of tests ran by a nested py.test process fails... so the failing output is correct).<commit_after>import py
import sys

here = py.magic.autopath().dirpath()
update_website = here.join('../../bin/_update_website.py').pyimport()

def test_rsync():
    temp = py.test.ensuretemp('update_website_rsync')
    pkgpath = temp.join('pkg')
    apipath = temp.join('apigen')
    pkgpath.ensure('foo/bar.txt', file=True).write('baz')
    pkgpath.ensure('spam/eggs.txt', file=True).write('spam')
    apipath.ensure('api/foo.html', file=True).write('<html />')
    apipath.ensure('source/spam.html', file=True).write('<html />')

    rsyncpath = temp.join('rsync')
    assert not rsyncpath.check()
    gateway = py.execnet.PopenGateway()
    update_website.rsync(pkgpath, apipath, gateway, rsyncpath.strpath)
    assert rsyncpath.check(dir=True)
    assert rsyncpath.join('pkg').check(dir=True)
    assert rsyncpath.join('pkg/spam/eggs.txt').read() == 'spam'
    assert rsyncpath.join('apigen').check(dir=True)
    assert rsyncpath.join('apigen/api/foo.html').read() == '<html />'

def setup_pkg(testname):
    temp = py.test.ensuretemp(testname)
    pkgpath = temp.ensure('pkg', dir=True)
    pyfile = pkgpath.ensure('mod.py').write(py.code.Source("""
        def foo(x):
            return x + 1
    """))
    testfile = pkgpath.ensure('test/test_mod.py').write(py.code.Source("""
        from pkg.sub import foo
        def test_foo():
            assert foo(1) == 2
    """))
    initfile = pkgpath.ensure('__init__.py').write(py.code.Source("""\
        import py
        from py.__.initpkg import initpkg
        initpkg(__name__, exportdefs={
            'sub.foo': ('./mod.py', 'foo'),
        })
    """))
    return pkgpath

def test_run_tests():
    if py.std.sys.platform == "win32":
        py.test.skip("update_website is not supposed to be run from win32")
    pkgpath = setup_pkg('update_website_run_tests')
    errors = update_website.run_tests(pkgpath)
    assert not errors
    assert pkgpath.join('../apigen').check(dir=True)
    assert pkgpath.join('../apigen/api/sub.foo.html').check(file=True)

def test_run_tests_failure():
    if py.std.sys.platform == "win32":
        py.test.skip("update_website is not supposed to be run from win32")
    pkgpath = setup_pkg('update_website_run_tests_failure')
    assert not pkgpath.join('../apigen').check(dir=True)
    pkgpath.ensure('../apigen', file=True)
    errors = update_website.run_tests(pkgpath, '> /dev/null 2>&1')
    assert errors # some error message

{'fraction_non_alphanumeric': 0.16420925065643305, 'fraction_numerical': 0.005049484952534842, 'mean_word_length': 3.4253798033958893, 'pattern_counts': {'":': 3, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2750326', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1654, 'n_words': 305}