示例#1
0
def test_reset_config():
    assert konch._cfg == konch.Config()
    konch.config({
        'banner': 'Foo bar'
    })
    konch.reset_config()
    assert konch._cfg == konch.Config()
示例#2
0
def test_config_list():
    assert konch._cfg == konch.Config()
    def my_func():
        return
    konch.config({
        'context': [my_func]
    })
    assert konch._cfg['context']['my_func'] == my_func
示例#3
0
def test_config_list():
    assert konch._cfg == konch.Config()

    def my_func():
        return

    konch.config({"context": [my_func]})
    assert konch._cfg["context"]["my_func"] == my_func
示例#4
0
def test_config_list():
    assert konch._cfg == konch.Config()

    def my_func():
        return

    konch.config({"context": [my_func]})
    assert konch._cfg["context"]["my_func"] == my_func
示例#5
0
def test_config_list():
    assert konch._cfg == konch.Config()

    def my_func():
        return

    konch.config({'context': [my_func]})
    assert konch._cfg['context']['my_func'] == my_func
示例#6
0
# vi: set ft=python :
"""Example .konchrc with named configs.

To use a named config, run:

    $ konch --name=trig

or

    $ konch -n trig
"""
import os
import sys
import math


import konch

# the default config
konch.config({"context": [os, sys], "banner": "The default shell"})

# A named config
konch.named_config(
    "trig", {"context": [math.sin, math.tan, math.cos], "banner": "The trig shell"}
)

konch.named_config(
    "func", {"context": [math.gamma, math.exp, math.log], "banner": "The func shell"}
)
示例#7
0
    assert 'already exists' in res.stderr
    assert res.returncode == 1


def test_default_banner(env):
    env.run('konch', 'init')
    res = env.run('konch', expect_stderr=True)
    assert_in_output(str(sys.version), res)


def test_config_file_not_found(env):
    res = env.run('konch', '-f', 'notfound', expect_stderr=True)
    assert 'not found' in res.stderr
    assert res.returncode == 0

TEST_CONFIG = """
import konch

konch.config({
    'banner': 'Test banner'
    'prompt': 'myprompt >>>'
})
"""


@pytest.fixture
def fileenv(request, env):
    fpath = os.path.join(env.base_path, 'testrc')
    with open(fpath, 'w') as fp:
        fp.write(TEST_CONFIG_WITH_NAMES)
    def finalize():
示例#8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import flask

import konch

konch.config({
    'context': {
        'request': flask.request,
        'url_for': flask.url_for,
        'Flask': flask.Flask,
        'render_template': flask.render_template
    }
})
示例#9
0
# -*- coding: utf-8 -*-
import datetime as dt

import konch
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

konch.config({
    "context": {
        "dt": dt,
        "pd": pd,
        "plt": plt,
        "np": np
    },
    "shell": "ipython",
    "ipy_autoreload": True,
    "ipy_extensions": [
        # Ipython extensions here
    ],
})
示例#10
0
# -*- coding: utf-8 -*-
# vi: set ft=python :
import flask
from flask import Flask
import konch

app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello world'

konch.config({
    'context': {
        'request': flask.request,
        'url_for': flask.url_for,
        'Flask': flask.Flask,
        'render_template': flask.render_template
    }
})

# Make sure we're in a request context so we can use
# url_for
ctx = app.test_request_context()
def setup():
    ctx.push()

def teardown():
    ctx.pop()
示例#11
0
def test_reset_config():
    assert konch._cfg == konch.Config()
    konch.config({'banner': 'Foo bar'})
    konch.reset_config()
    assert konch._cfg == konch.Config()
示例#12
0
@pytest.mark.skipif(HAS_PTPYTHON, reason='test incompatible with ptpython')
def test_default_banner(env):
    env.run('konch', 'init')
    res = env.run('konch', expect_stderr=True)
    assert_in_output(str(sys.version), res)


@pytest.mark.skipif(HAS_PTPYTHON, reason='test incompatible with ptpython')
def test_config_file_not_found(env):
    res = env.run('konch', '-f', 'notfound', expect_stderr=True)
    assert 'not found' in res.stderr
    assert res.returncode == 0


TEST_CONFIG = """
import konch

konch.config({
    'banner': 'Test banner',
    'prompt': 'myprompt >>>'
})
"""


@pytest.fixture
def fileenv(request, env):
    fpath = os.path.join(env.base_path, 'testrc')
    with open(fpath, 'w') as fp:
        fp.write(TEST_CONFIG)
示例#13
0
    $ konch --name=trig

or

    $ konch -n trig
"""
import os
import sys
import math


import konch

# the default config
konch.config({
    'context': [os, sys],
    'banner': 'The default shell'
})

# A named config
konch.named_config('trig', {
    'context': [math.sin, math.tan, math.cos],
    'banner': 'The trig shell'
})

konch.named_config('func', {
    'context': [math.gamma, math.exp, math.log],
    'banner': 'The func shell'
})
示例#14
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random

import konch

banner = '''
"Probability is not a mere computation of odds on the dice or more complicated
variants; it is the acceptance of the lack of certainty in our knowledge and
the development of methods for dealing with our ignorance."
- Nassim Nickolas Taleb
'''

konch.config({
    'context': [random.randint, random.random, random.choice],
    'banner': banner,
    'shell': konch.IPythonShell,
})
示例#15
0
    res = env.run("konch", expect_stderr=True)
    assert_in_output(str(sys.version), res)


@pytest.mark.skipif(HAS_PTPYTHON, reason="test incompatible with ptpython")
def test_config_file_not_found(env):
    res = env.run("konch",
                  "-f",
                  "notfound",
                  expect_stderr=True,
                  expect_error=True)
    assert '"notfound" not found' in res.stderr
    assert res.returncode == 1


TEST_CONFIG = """
import konch

konch.config({
    'banner': 'Test banner',
    'prompt': 'myprompt >>>'
})
"""


@pytest.fixture
def fileenv(request, env):
    fpath = Path(env.base_path) / "testrc"
    with fpath.open("w") as fp:
        fp.write(TEST_CONFIG)
示例#16
0
def test_reset_config():
    assert konch._cfg == konch.Config()
    konch.config({"banner": "Foo bar"})
    konch.reset_config()
    assert konch._cfg == konch.Config()
示例#17
0
def test_config():
    assert konch._cfg == konch.Config()
    konch.config({"banner": "Foo bar"})
    assert konch._cfg["banner"] == "Foo bar"
示例#18
0
# -*- coding: utf-8 -*-
# vi: set ft=python :
import konch
import requests

konch.config({
    'context': {
        'httpget': requests.get,
        'httppost': requests.post,
        'httpput': requests.put,
        'httpdelete': requests.delete
    },
    'banner': 'A humanistic HTTP shell'
})
示例#19
0
# vi: set ft=python :
"""Example .konchrc with named configs.

To use a named config, run:

    $ konch --name=trig

or

    $ konch -n trig
"""
import os
import sys
import math

import konch

# the default config
konch.config({"context": [os, sys], "banner": "The default shell"})

# A named config
konch.named_config("trig", {
    "context": [math.sin, math.tan, math.cos],
    "banner": "The trig shell"
})

konch.named_config("func", {
    "context": [math.gamma, math.exp, math.log],
    "banner": "The func shell"
})
示例#20
0
import datetime

import konch
import pandas
import numpy

konch.config(
    {
        "context": [datetime, pandas, numpy],
        "shell": "ipython",
        "ipy_autoreload": True,
        "ipy_extensions": [
            # Ipython extensions here
        ],
    }
)
示例#21
0
def test_config():
    assert konch._cfg == konch.Config()
    konch.config({'banner': 'Foo bar'})
    assert konch._cfg['banner'] == 'Foo bar'
示例#22
0
# vi: set ft=python :
import flask
from flask import Flask
import konch

app = Flask(__name__)


@app.route("/")
def index():
    return "Hello world"


konch.config({"context": [flask.url_for, flask.Flask, flask.render_template]})

# Make sure we're in a request context so we can use
# url_for
ctx = app.test_request_context()


def setup():
    ctx.push()
    app.preprocess_request()


def teardown():
    app.process_response(app.response_class())
    ctx.pop()
示例#23
0
# -*- coding: utf-8 -*-
import datetime as dt

import konch
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

konch.config({
    'context': {
        'dt': dt,
        'pd': pd,
        'plt': plt,
        'np': np,
    },
    'shell': 'ipython',
    'ipy_autoreload': True,
    'ipy_extensions': [
        # Ipython extensions here
    ]
})
示例#24
0
# -*- coding: utf-8 -*-
import konch
import requests

konch.config({
    'context': {
        'httpget': requests.get,
        'httppost': requests.post,
        'httpput': requests.put,
        'httpdelete': requests.delete
    },
    'banner': 'A humanistic HTTP shell'
})
示例#25
0
# -*- coding: utf-8 -*-
# vi: set ft=python :
import konch
import requests

konch.config({
    "context": {
        "httpget": requests.get,
        "httppost": requests.post,
        "httpput": requests.put,
        "httpdelete": requests.delete,
    },
    "banner": "A humanistic HTTP shell",
})
示例#26
0
# vi: set ft=python :
import konch
import requests

konch.config({
    "context": [requests.get, requests.post, requests.put, requests.delete],
    "banner":
    "A humanistic HTTP shell",
})
示例#27
0
# -*- coding: utf-8 -*-
# vi: set ft=python :

import random

import konch

banner = """
"Probability is not a mere computation of odds on the dice or more complicated
variants; it is the acceptance of the lack of certainty in our knowledge and
the development of methods for dealing with our ignorance."
- Nassim Nickolas Taleb
"""

konch.config(
    {
        "context": [random.randint, random.random, random.choice],
        "banner": banner,
        "shell": konch.IPythonShell,
    }
)
示例#28
0
def test_config():
    assert konch._cfg == konch.Config()
    konch.config({
        'banner': 'Foo bar'
    })
    assert konch._cfg['banner'] == 'Foo bar'
示例#29
0
    $ konch --name=trig

or

    $ konch -n trig
"""
import os
import sys
import math


import konch

# the default config
konch.config({
    'context': [os, sys],
    'banner': 'The default shell'
})

# A named config
konch.named_config('trig', {
    'context': [math.sin, math.tan, math.cos],
    'banner': 'The trig shell'
})

konch.named_config('func', {
    'context': [math.gamma, math.exp, math.log],
    'banner': 'The func shell'
})
示例#30
0
# vi: set ft=python :
import konch
import requests

konch.config(
    {
        "context": [requests.get, requests.post, requests.put, requests.delete],
        "banner": "A humanistic HTTP shell",
    }
)
示例#31
0
def test_config():
    assert konch._cfg == konch.Config()
    konch.config({"banner": "Foo bar"})
    assert konch._cfg["banner"] == "Foo bar"
示例#32
0
from flask import Flask
import konch

app = Flask(__name__)


@app.route("/")
def index():
    return "Hello world"


konch.config(
    {
        "context": {
            "request": flask.request,
            "url_for": flask.url_for,
            "Flask": flask.Flask,
            "render_template": flask.render_template,
        }
    }
)

# Make sure we're in a request context so we can use
# url_for
ctx = app.test_request_context()


def setup():
    ctx.push()
    app.preprocess_request()

示例#33
0
def test_reset_config():
    assert konch._cfg == konch.Config()
    konch.config({"banner": "Foo bar"})
    konch.reset_config()
    assert konch._cfg == konch.Config()
示例#34
0
# -*- coding: utf-8 -*-
# vi: set ft=python :

import random

import konch

banner = '''
"Probability is not a mere computation of odds on the dice or more complicated
variants; it is the acceptance of the lack of certainty in our knowledge and
the development of methods for dealing with our ignorance."
- Nassim Nickolas Taleb
'''

konch.config({
    'context': [random.randint, random.random, random.choice],
    'banner': banner,
    'shell': konch.IPythonShell,
})