def test_reset_config(): assert konch._cfg == konch.Config() konch.config({ 'banner': 'Foo bar' }) konch.reset_config() assert konch._cfg == konch.Config()
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
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
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
# 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"} )
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():
#!/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 } })
# -*- 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 ], })
# -*- 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()
def test_reset_config(): assert konch._cfg == konch.Config() konch.config({'banner': 'Foo bar'}) konch.reset_config() assert konch._cfg == konch.Config()
@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)
$ 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' })
#!/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, })
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)
def test_reset_config(): assert konch._cfg == konch.Config() konch.config({"banner": "Foo bar"}) konch.reset_config() assert konch._cfg == konch.Config()
def test_config(): assert konch._cfg == konch.Config() konch.config({"banner": "Foo bar"}) assert konch._cfg["banner"] == "Foo bar"
# -*- 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' })
# 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" })
import datetime import konch import pandas import numpy konch.config( { "context": [datetime, pandas, numpy], "shell": "ipython", "ipy_autoreload": True, "ipy_extensions": [ # Ipython extensions here ], } )
def test_config(): assert konch._cfg == konch.Config() konch.config({'banner': 'Foo bar'}) assert konch._cfg['banner'] == 'Foo bar'
# 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()
# -*- 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 ] })
# -*- 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' })
# -*- 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", })
# vi: set ft=python : import konch import requests konch.config({ "context": [requests.get, requests.post, requests.put, requests.delete], "banner": "A humanistic HTTP shell", })
# -*- 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, } )
def test_config(): assert konch._cfg == konch.Config() konch.config({ 'banner': 'Foo bar' }) assert konch._cfg['banner'] == 'Foo bar'
# vi: set ft=python : import konch import requests konch.config( { "context": [requests.get, requests.post, requests.put, requests.delete], "banner": "A humanistic HTTP shell", } )
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()
# -*- 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, })