Esempio n. 1
0
def test_get_py_filename():
    os.chdir(TMP_TEST_DIR)
    for win32 in (True, False):
        with make_tempfile('foo.py'):
            nt.assert_equal(
                path.get_py_filename('foo.py', force_win32=win32), 'foo.py')
            nt.assert_equal(
                path.get_py_filename('foo', force_win32=win32), 'foo.py')
        with make_tempfile('foo'):
            nt.assert_equal(
                path.get_py_filename('foo', force_win32=win32), 'foo')
            nt.assert_raises(
                IOError, path.get_py_filename, 'foo.py', force_win32=win32)
        nt.assert_raises(
            IOError, path.get_py_filename, 'foo', force_win32=win32)
        nt.assert_raises(
            IOError, path.get_py_filename, 'foo.py', force_win32=win32)
        true_fn = 'foo with spaces.py'
        with make_tempfile(true_fn):
            nt.assert_equal(
                path.get_py_filename('foo with spaces', force_win32=win32), true_fn)
            nt.assert_equal(
                path.get_py_filename('foo with spaces.py', force_win32=win32), true_fn)
            if win32:
                nt.assert_equal(
                    path.get_py_filename('"foo with spaces.py"', force_win32=True), true_fn)
                nt.assert_equal(
                    path.get_py_filename("'foo with spaces.py'", force_win32=True), true_fn)
            else:
                nt.assert_raises(
                    IOError, path.get_py_filename, '"foo with spaces.py"', force_win32=False)
                nt.assert_raises(
                    IOError, path.get_py_filename, "'foo with spaces.py'", force_win32=False)
Esempio n. 2
0
def test_get_py_filename():
    os.chdir(TMP_TEST_DIR)
    with make_tempfile('foo.py'):
        nt.assert_equal(path.get_py_filename('foo.py'), 'foo.py')
        nt.assert_equal(path.get_py_filename('foo'), 'foo.py')
    with make_tempfile('foo'):
        nt.assert_equal(path.get_py_filename('foo'), 'foo')
        nt.assert_raises(IOError, path.get_py_filename, 'foo.py')
    nt.assert_raises(IOError, path.get_py_filename, 'foo')
    nt.assert_raises(IOError, path.get_py_filename, 'foo.py')
    true_fn = 'foo with spaces.py'
    with make_tempfile(true_fn):
        nt.assert_equal(path.get_py_filename('foo with spaces'), true_fn)
        nt.assert_equal(path.get_py_filename('foo with spaces.py'), true_fn)
        nt.assert_raises(IOError, path.get_py_filename, '"foo with spaces.py"')
        nt.assert_raises(IOError, path.get_py_filename, "'foo with spaces.py'")
Esempio n. 3
0
def test_get_py_filename():
    os.chdir(TMP_TEST_DIR)
    with make_tempfile('foo.py'):
        nt.assert_equal(path.get_py_filename('foo.py'), 'foo.py')
        nt.assert_equal(path.get_py_filename('foo'), 'foo.py')
    with make_tempfile('foo'):
        nt.assert_equal(path.get_py_filename('foo'), 'foo')
        nt.assert_raises(IOError, path.get_py_filename, 'foo.py')
    nt.assert_raises(IOError, path.get_py_filename, 'foo')
    nt.assert_raises(IOError, path.get_py_filename, 'foo.py')
    true_fn = 'foo with spaces.py'
    with make_tempfile(true_fn):
        nt.assert_equal(path.get_py_filename('foo with spaces'), true_fn)
        nt.assert_equal(path.get_py_filename('foo with spaces.py'), true_fn)
        nt.assert_raises(IOError, path.get_py_filename, '"foo with spaces.py"')
        nt.assert_raises(IOError, path.get_py_filename, "'foo with spaces.py'")
Esempio n. 4
0
def test_get_py_filename():
    os.chdir(TMP_TEST_DIR)
    with make_tempfile("foo.py"):
        assert path.get_py_filename("foo.py") == "foo.py"
        assert path.get_py_filename("foo") == "foo.py"
    with make_tempfile("foo"):
        assert path.get_py_filename("foo") == "foo"
        pytest.raises(IOError, path.get_py_filename, "foo.py")
    pytest.raises(IOError, path.get_py_filename, "foo")
    pytest.raises(IOError, path.get_py_filename, "foo.py")
    true_fn = "foo with spaces.py"
    with make_tempfile(true_fn):
        assert path.get_py_filename("foo with spaces") == true_fn
        assert path.get_py_filename("foo with spaces.py") == true_fn
        pytest.raises(IOError, path.get_py_filename, '"foo with spaces.py"')
        pytest.raises(IOError, path.get_py_filename, "'foo with spaces.py'")
Esempio n. 5
0
def test_get_py_filename():
    os.chdir(TMP_TEST_DIR)
    for win32 in (True, False):
        with make_tempfile('foo.py'):
            nt.assert_equal(path.get_py_filename('foo.py', force_win32=win32),
                            'foo.py')
            nt.assert_equal(path.get_py_filename('foo', force_win32=win32),
                            'foo.py')
        with make_tempfile('foo'):
            nt.assert_equal(path.get_py_filename('foo', force_win32=win32),
                            'foo')
            nt.assert_raises(IOError,
                             path.get_py_filename,
                             'foo.py',
                             force_win32=win32)
        nt.assert_raises(IOError,
                         path.get_py_filename,
                         'foo',
                         force_win32=win32)
        nt.assert_raises(IOError,
                         path.get_py_filename,
                         'foo.py',
                         force_win32=win32)
        true_fn = 'foo with spaces.py'
        with make_tempfile(true_fn):
            nt.assert_equal(
                path.get_py_filename('foo with spaces', force_win32=win32),
                true_fn)
            nt.assert_equal(
                path.get_py_filename('foo with spaces.py', force_win32=win32),
                true_fn)
            if win32:
                nt.assert_equal(
                    path.get_py_filename('"foo with spaces.py"',
                                         force_win32=True), true_fn)
                nt.assert_equal(
                    path.get_py_filename("'foo with spaces.py'",
                                         force_win32=True), true_fn)
            else:
                nt.assert_raises(IOError,
                                 path.get_py_filename,
                                 '"foo with spaces.py"',
                                 force_win32=False)
                nt.assert_raises(IOError,
                                 path.get_py_filename,
                                 "'foo with spaces.py'",
                                 force_win32=False)
def test_writeandexecute_content():
    ip = get_ipython()

    with tt.AssertPrints("'writeandexecute' magic loaded"):
        ip.run_cell("%reload_ext ipyext.writeandexecute")

    ip.run_cell("a = 0")

    with tt.make_tempfile(TF_NAME):

        # run something ones, to get the file setup
        with tt.AssertPrints("Hello world"):
            ip.run_cell(
                "%%writeandexecute -i bla xxx_temp_foo\nprint('Hello world')")

        with io.open(TF_NAME, 'a', encoding='utf-8') as tf:
            tf.write(u"\n# -- ==blub== --\n")

        # only one identifier
        with tt.AssertPrints("Exception: Found only one line with identifier",
                             suppress=False):
            ip.run_cell(
                "%%writeandexecute -d -i blub xxx_temp_foo\nprint('Hello world1')\na=1"
            )

        #This should not be executed...
        with tt.AssertPrints("a=0"):
            ip.run_cell("print('a=%s' % a)")

        with io.open(TF_NAME, 'a', encoding='utf-8') as tf:
            tf.write(u"\n# -- ==blub== --\n")

        # two should work
        with tt.AssertPrints("Hello world2", suppress=False):
            ip.run_cell(
                "%%writeandexecute -d -i blub xxx_temp_foo\nprint('Hello world2')\na=2"
            )

        with io.open(TF_NAME, 'a', encoding='utf-8') as tf:
            tf.write(u"\n# -- ==blub== --\n")

        # three is bad again identifier
        with tt.AssertPrints(
                "Exception: Found more than two lines with identifier",
                suppress=False):
            ip.run_cell(
                "%%writeandexecute -d -i blub xxx_temp_foo\nprint('Hello world3')\na=3"
            )

        # make sure that only the second one got executed...
        with tt.AssertPrints("a=2"):
            ip.run_cell("print('a=%s' % a)")

        # make sure that only the second one got written to the file
        with io.open(TF_NAME, 'r', encoding='utf-8') as tf:
            content = tf.read()
            nt.assert_in("print('Hello world2')", content)
def test_writeandexecute_content():
    ip = get_ipython()

    with tt.AssertPrints("'writeandexecute' magic loaded"):
        ip.run_cell("%reload_ext ipyext.writeandexecute")

    ip.run_cell("a = 0")

    with tt.make_tempfile(TF_NAME):

        # run something ones, to get the file setup
        with tt.AssertPrints("Hello world"):
            ip.run_cell("%%writeandexecute -i bla xxx_temp_foo\nprint('Hello world')")

        with io.open(TF_NAME, 'a', encoding='utf-8') as tf:
            tf.write(u"\n# -- ==blub== --\n")

        # only one identifier
        with tt.AssertPrints("Exception: Found only one line with identifier", suppress=False):
            ip.run_cell("%%writeandexecute -d -i blub xxx_temp_foo\nprint('Hello world1')\na=1")

        #This should not be executed...
        with tt.AssertPrints("a=0"):
            ip.run_cell("print('a=%s' % a)")

        with io.open(TF_NAME, 'a', encoding='utf-8') as tf:
            tf.write(u"\n# -- ==blub== --\n")

        # two should work
        with tt.AssertPrints("Hello world2", suppress=False):
            ip.run_cell("%%writeandexecute -d -i blub xxx_temp_foo\nprint('Hello world2')\na=2")

        with io.open(TF_NAME, 'a', encoding='utf-8') as tf:
            tf.write(u"\n# -- ==blub== --\n")

        # three is bad again identifier
        with tt.AssertPrints("Exception: Found more than two lines with identifier", suppress=False):
            ip.run_cell("%%writeandexecute -d -i blub xxx_temp_foo\nprint('Hello world3')\na=3")

        # make sure that only the second one got executed...
        with tt.AssertPrints("a=2"):
            ip.run_cell("print('a=%s' % a)")

        # make sure that only the second one got written to the file
        with io.open(TF_NAME, 'r', encoding='utf-8') as tf:
            content = tf.read()
            nt.assert_in("print('Hello world2')", content)
def test_get_init_3():
    """get_init can't find __init__.pyc in this testdir"""
    with make_tempfile(join(TMP_TEST_DIR, "__init__.pyc")):
        assert mp.get_init(TMP_TEST_DIR) is None
def test_get_init_2():
    """See if get_init can find __init__.pyw in this testdir"""
    with make_tempfile(join(TMP_TEST_DIR, "__init__.pyw")):
        assert mp.get_init(TMP_TEST_DIR)
Esempio n. 10
0
def test_get_init_3():
    """get_init can't find __init__.pyc in this testdir"""
    with make_tempfile(join(TMP_TEST_DIR, "__init__.pyc")):
        nt.assert_is_none(mp.get_init(TMP_TEST_DIR))
Esempio n. 11
0
def test_get_init_2():
    """See if get_init can find __init__.pyw in this testdir"""
    with make_tempfile(join(TMP_TEST_DIR, "__init__.pyw")):
        assert mp.get_init(TMP_TEST_DIR)