<commit_before>from __future__ import generators
import py

from py.__.test.config import gettopdir

def test_tmpdir():
    d1 = py.test.ensuretemp('hello') 
    d2 = py.test.ensuretemp('hello') 
    assert d1 == d2
    assert d1.check(dir=1) 

def test_config_cmdline_options(): 
    o = py.test.ensuretemp('configoptions') 
    o.ensure("conftest.py").write(py.code.Source(""" 
        import py
        def _callback(option, opt_str, value, parser, *args, **kwargs):
            option.tdest = True
        Option = py.test.config.Option
        option = py.test.config.addoptions("testing group", 
            Option('-G', '--glong', action="store", default=42,
                   type="int", dest="gdest", help="g value."), 
            # XXX note: special case, option without a destination
            Option('-T', '--tlong', action="callback", callback=_callback,
                    help='t value'),
            )
        """))
    old = o.chdir() 
    try: 
        config = py.test.config._reparse(['-G', '17'])
    finally: 
        old.chdir() 
    assert config.option.gdest == 17 

def test_config_cmdline_options_only_lowercase(): 
    o = py.test.ensuretemp('test_config_cmdline_options_only_lowercase')
    o.ensure("conftest.py").write(py.code.Source(""" 
        import py
        Option = py.test.config.Option
        options = py.test.config.addoptions("testing group", 
            Option('-g', '--glong', action="store", default=42,
                   type="int", dest="gdest", help="g value."), 
            )
        """))
    old = o.chdir() 
    try: 
        py.test.raises(ValueError, """
            py.test.config._reparse(['-g', '17'])
        """)
    finally: 
        old.chdir() 

def test_parsing_again_fails():
    dir = py.test.ensuretemp("parsing_again_fails")
    config = py.test.config._reparse([str(dir)])
    py.test.raises(AssertionError, "config.parse([])")

def test_config_getvalue_honours_conftest():
    o = py.test.ensuretemp('testconfigget') 
    o.ensure("conftest.py").write("x=1")
    o.ensure("sub", "conftest.py").write("x=2 ; y = 3")
    config = py.test.config._reparse([str(o)])
    assert config.getvalue("x") == 1
    assert config.getvalue("x", o.join('sub')) == 2
    py.test.raises(KeyError, "config.getvalue('y')")
    config = py.test.config._reparse([str(o.join('sub'))])
    assert config.getvalue("x") == 2
    assert config.getvalue("y") == 3
    assert config.getvalue("x", o) == 1
    py.test.raises(KeyError, 'config.getvalue("y", o)')


def test_siblingconftest_fails_maybe():
    from py.__.test import config
    cfg = config.Config()
    o = py.test.ensuretemp('siblingconftest')
    o.ensure("__init__.py")
    o.ensure("sister1", "__init__.py")
    o.ensure("sister1", "conftest.py").write(py.code.Source("""
        x = 2
    """))
        
    o.ensure("sister2", "__init__.py")
    o.ensure("sister2", "conftest.py").write(py.code.Source("""
        raise SyntaxError
    """))

    assert cfg.getvalue(path=o.join('sister1'), name='x') == 2
    old = o.chdir()
    try:
        print py.process.cmdexec("py.test sister1")
        o.join('sister1').chdir()
        print py.process.cmdexec("py.test") 
    finally:
        old.chdir()

def test_config_overwrite():
    o = py.test.ensuretemp('testconfigget') 
    o.ensure("conftest.py").write("x=1")
    config = py.test.config._reparse([str(o)])
    assert config.getvalue('x') == 1
    config._overwrite('x', 2)
    assert config.getvalue('x') == 2
    config = py.test.config._reparse([str(o)])
    assert config.getvalue('x') == 1

def test_gettopdir():
    tmp = py.test.ensuretemp("topdir")
    assert gettopdir([tmp]) == tmp
    topdir =gettopdir([tmp.join("hello"), tmp.join("world")])
    assert topdir == tmp 

def test_gettopdir_pypkg():
    tmp = py.test.ensuretemp("topdir2")
    a = tmp.ensure('a', dir=1)
    b = tmp.ensure('a', 'b', '__init__.py')
    c = tmp.ensure('a', 'b', 'c.py')
    Z = tmp.ensure('Z', dir=1)<commit_msg>[svn r37326] Fixed exec command on win32<commit_after>from __future__ import generators
import py

from py.__.test.config import gettopdir

def test_tmpdir():
    d1 = py.test.ensuretemp('hello') 
    d2 = py.test.ensuretemp('hello') 
    assert d1 == d2
    assert d1.check(dir=1) 

def test_config_cmdline_options(): 
    o = py.test.ensuretemp('configoptions') 
    o.ensure("conftest.py").write(py.code.Source(""" 
        import py
        def _callback(option, opt_str, value, parser, *args, **kwargs):
            option.tdest = True
        Option = py.test.config.Option
        option = py.test.config.addoptions("testing group", 
            Option('-G', '--glong', action="store", default=42,
                   type="int", dest="gdest", help="g value."), 
            # XXX note: special case, option without a destination
            Option('-T', '--tlong', action="callback", callback=_callback,
                    help='t value'),
            )
        """))
    old = o.chdir() 
    try: 
        config = py.test.config._reparse(['-G', '17'])
    finally: 
        old.chdir() 
    assert config.option.gdest == 17 

def test_config_cmdline_options_only_lowercase(): 
    o = py.test.ensuretemp('test_config_cmdline_options_only_lowercase')
    o.ensure("conftest.py").write(py.code.Source(""" 
        import py
        Option = py.test.config.Option
        options = py.test.config.addoptions("testing group", 
            Option('-g', '--glong', action="store", default=42,
                   type="int", dest="gdest", help="g value."), 
            )
        """))
    old = o.chdir() 
    try: 
        py.test.raises(ValueError, """
            py.test.config._reparse(['-g', '17'])
        """)
    finally: 
        old.chdir() 

def test_parsing_again_fails():
    dir = py.test.ensuretemp("parsing_again_fails")
    config = py.test.config._reparse([str(dir)])
    py.test.raises(AssertionError, "config.parse([])")

def test_config_getvalue_honours_conftest():
    o = py.test.ensuretemp('testconfigget') 
    o.ensure("conftest.py").write("x=1")
    o.ensure("sub", "conftest.py").write("x=2 ; y = 3")
    config = py.test.config._reparse([str(o)])
    assert config.getvalue("x") == 1
    assert config.getvalue("x", o.join('sub')) == 2
    py.test.raises(KeyError, "config.getvalue('y')")
    config = py.test.config._reparse([str(o.join('sub'))])
    assert config.getvalue("x") == 2
    assert config.getvalue("y") == 3
    assert config.getvalue("x", o) == 1
    py.test.raises(KeyError, 'config.getvalue("y", o)')


def test_siblingconftest_fails_maybe():
    from py.__.test import config
    cfg = config.Config()
    o = py.test.ensuretemp('siblingconftest')
    o.ensure("__init__.py")
    o.ensure("sister1", "__init__.py")
    o.ensure("sister1", "conftest.py").write(py.code.Source("""
        x = 2
    """))
        
    o.ensure("sister2", "__init__.py")
    o.ensure("sister2", "conftest.py").write(py.code.Source("""
        raise SyntaxError
    """))

    assert cfg.getvalue(path=o.join('sister1'), name='x') == 2
    old = o.chdir()
    try:
        pytestpath = py.magic.autopath().dirpath().dirpath().dirpath().join(
                        'bin/py.test')
        print py.process.cmdexec('python "%s" sister1' % (pytestpath,))
        o.join('sister1').chdir()
        print py.process.cmdexec('python "%s"' % (pytestpath,))
    finally:
        old.chdir()

def test_config_overwrite():
    o = py.test.ensuretemp('testconfigget') 
    o.ensure("conftest.py").write("x=1")
    config = py.test.config._reparse([str(o)])
    assert config.getvalue('x') == 1
    config._overwrite('x', 2)
    assert config.getvalue('x') == 2
    config = py.test.config._reparse([str(o)])
    assert config.getvalue('x') == 1

def test_gettopdir():
    tmp = py.test.ensuretemp("topdir")
    assert gettopdir([tmp]) == tmp
    topdir =gettopdir([tmp.join("hello"), tmp.join("world")])
    assert topdir == tmp 

def test_gettopdir_pypkg():
    tmp = py.test.ensuretemp("topdir2")
    a = tmp.ensure('a', dir=1)
    b = tmp.ensure('a', 'b', '__init__.py')
    c = tmp.ensure('a', 'b', 'c.py')
    Z = tmp.ensure('Z', dir=1)
{'fraction_non_alphanumeric': 0.18091378039793662, 'fraction_numerical': 0.010930975190370916, 'mean_word_length': 2.783921933085502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1857468', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2805, 'n_words': 482}