• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python common.run_python_code函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中testcases.common.run_python_code函数的典型用法代码示例。如果您正苦于以下问题:Python run_python_code函数的具体用法?Python run_python_code怎么用?Python run_python_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了run_python_code函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testExample1

    def testExample1(self):
        with common.CopyFiles([os.path.join("testcases", "data", "bitstampUSD-2.csv")], "bitstampUSD.csv"):
            code = """import sys
sys.path.append('samples')
import bccharts_example_1
bccharts_example_1.main()
"""
            common.run_python_code(code)
            lines = common.get_file_lines("30min-bitstampUSD.csv")
            self.assertTrue(common.compare_head("30min-bitstampUSD-2.csv", lines[0:10], "testcases/data"))
            self.assertTrue(common.compare_tail("30min-bitstampUSD-2.csv", lines[-10:], "testcases/data"))
            os.remove("30min-bitstampUSD.csv")
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:12,代码来源:doc_test.py


示例2: testMarketTiming

    def testMarketTiming(self):
        files = []
        instruments = ["VTI", "VEU", "IEF", "VNQ", "DBC", "SPY"]
        for year in range(2007, 2013+1):
            for symbol in instruments:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        # The differences in the output are related to key ordering in dicts.
        if six.PY3:
            expected_output = "market_timing.output.37"
        else:
            expected_output = "market_timing.output.27"

        with common.CopyFiles(files, "."):
            code = """import sys
sys.path.append('samples')
import market_timing
market_timing.main(False)
"""
            res = common.run_python_code(code)
            self.assertTrue(res.exit_ok())
            self.assertEqual(
                res.get_output_lines()[-10:],
                common.tail_file(expected_output, 10)
            )
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:26,代码来源:doc_test.py


示例3: testCSVFeed

    def testCSVFeed(self):
        with common.CopyFiles([os.path.join("samples", "data", "quandl_gold_2.csv")], "."):
            code = """import sys
sys.path.append('samples')
import csvfeed_1
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_head("csvfeed_1.output", lines[0:10]))
            self.assertTrue(common.compare_tail("csvfeed_1.output", lines[-10:-1]))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:9,代码来源:doc_test.py


示例4: testBacktestingLog2

    def testBacktestingLog2(self):
            code = """from testcases import logger_test_2
logger_test_2.main()
"""
            lines = common.run_python_code(code).split("\n")
            self.assertEqual(len(lines), 4)
            self.assertEqual(lines[0], "2000-01-01 00:00:00 strategy [INFO] bla")
            self.assertTrue(lines[1].find("2000-01-02 00:00:00 broker.backtesting [DEBUG] Not enough money to fill order") == 0)
            self.assertEqual(lines[2], "2000-01-02 00:00:00 strategy [INFO] bla")
            self.assertEqual(lines[3], "")
开发者ID:arippbbc,项目名称:pyalgotrade,代码行数:10,代码来源:logger_test.py


示例5: testExample2

    def testExample2(self):
        with common.CopyFiles([os.path.join("testcases", "data", "30min-bitstampUSD-2.csv")], "30min-bitstampUSD.csv"):
            code = """import sys
sys.path.append('samples')
import bccharts_example_2
bccharts_example_2.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_head("bccharts_example_2.output", lines[0:10], "testcases/data"))
            self.assertTrue(common.compare_tail("bccharts_example_2.output", lines[-10:-1], "testcases/data"))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:10,代码来源:doc_test.py


示例6: testTutorial1MtGox

    def testTutorial1MtGox(self):
        with common.CopyFiles([os.path.join("samples", "data", "trades-mtgox-usd-2013-03.csv")], "."):
            code = """import sys
sys.path.append('samples')
import tutorial_mtgox_1
tutorial_mtgox_1.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_head("tutorial_mtgox_1.output", lines[0:10]))
            self.assertTrue(common.compare_tail("tutorial_mtgox_1.output", lines[-10:-1]))
开发者ID:arippbbc,项目名称:pyalgotrade,代码行数:10,代码来源:doc_test.py


示例7: testBacktestingLog1

    def testBacktestingLog1(self):
            code = """from testcases import logger_test_1
logger_test_1.main()
"""
            res = common.run_python_code(code)
            expectedLines = [
                "2000-01-01 00:00:00 strategy [INFO] bla",
                "2000-01-01 00:00:00 custom [INFO] ble",
            ]
            self.assertEqual(res.get_output_lines(), expectedLines)
            self.assertTrue(res.exit_ok())
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:11,代码来源:logger_test.py


示例8: testBacktestingLog1

    def testBacktestingLog1(self):
            code = """from testcases import logger_test_1
logger_test_1.main()
"""
            lines = common.run_python_code(code).split("\n")
            expectedLines = [
                "2000-01-01 00:00:00 strategy [INFO] bla",
                "2000-01-01 00:00:00 custom [INFO] ble",
                "",
            ]
            self.assertEqual(lines, expectedLines)
开发者ID:arippbbc,项目名称:pyalgotrade,代码行数:11,代码来源:logger_test.py


示例9: testNonBacktestingLog3

    def testNonBacktestingLog3(self):
            code = """from testcases import logger_test_3
logger_test_3.main()
"""
            lines = common.run_python_code(code).split("\n")

            now = datetime.datetime.now()
            self.assertEqual(len(lines), 3)
            for line in lines[:-1]:
                self.assertEqual(line.find(str(now.date())), 0)
            self.assertNotEqual(lines[0].find("strategy [INFO] bla"), -1)
            self.assertNotEqual(lines[1].find("custom [INFO] ble"), -1)
开发者ID:arippbbc,项目名称:pyalgotrade,代码行数:12,代码来源:logger_test.py


示例10: testBacktestingLog2

    def testBacktestingLog2(self):
            code = """from testcases import logger_test_2
logger_test_2.main()
"""
            res = common.run_python_code(code)
            self.assertEqual(len(res.get_output_lines()), 3)
            self.assertEqual(res.get_output_lines()[0], "2000-01-01 00:00:00 strategy [INFO] bla")
            self.assertEqual(
                res.get_output_lines()[1],
                "2000-01-02 00:00:00 broker.backtesting [DEBUG] Not enough cash to fill orcl order [1] for 1 share/s"
            )
            self.assertEqual(res.get_output_lines()[2], "2000-01-02 00:00:00 strategy [INFO] bla")
            self.assertTrue(res.exit_ok())
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:13,代码来源:logger_test.py


示例11: testNonBacktestingLog3

    def testNonBacktestingLog3(self):
            code = """from testcases import logger_test_3
logger_test_3.main()
"""
            res = common.run_python_code(code)

            now = datetime.datetime.now()
            self.assertEqual(len(res.get_output_lines()), 2)
            for line in res.get_output_lines(True):
                self.assertEqual(line.find(str(now.date())), 0)
            self.assertNotEqual(res.get_output_lines()[0].find("strategy [INFO] bla"), -1)
            self.assertNotEqual(res.get_output_lines()[1].find("custom [INFO] ble"), -1)
            self.assertTrue(res.exit_ok())
开发者ID:Chin-I,项目名称:pyalgotrade,代码行数:13,代码来源:logger_test.py


示例12: testBBands

    def testBBands(self):
        files = []
        for year in range(2011, 2013):
            for symbol in ["yhoo"]:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        with common.CopyFiles(files, "."):
            code = """import sys
sys.path.append('samples')
import bbands
bbands.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_tail("bbands.output", lines[-2:-1]))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:15,代码来源:doc_test.py


示例13: testErnieChanGldVsGdx

    def testErnieChanGldVsGdx(self):
        files = []
        for year in range(2006, 2013):
            for symbol in ["gld", "gdx"]:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        with common.CopyFiles(files, "."):
            code = """import sys
sys.path.append('samples')
import statarb_erniechan
statarb_erniechan.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_tail("statarb_erniechan.output", lines[-2:-1]))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:15,代码来源:doc_test.py


示例14: testEventStudy

    def testEventStudy(self):
        files = []
        for year in range(2008, 2010):
            for symbol in ["AA", "AES", "AIG"]:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        with common.CopyFiles(files, "."):
            code = """import sys
sys.path.append('samples')
import eventstudy
eventstudy.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_tail("eventstudy.output", lines[-2:-1]))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:15,代码来源:doc_test.py


示例15: testRSI2

    def testRSI2(self):
        files = []
        for year in range(2009, 2013):
            for symbol in ["DIA"]:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        with common.CopyFiles(files, "."):
            code = """import sys
sys.path.append('samples')
import rsi2_sample
rsi2_sample.main(False)
"""
            res = common.run_python_code(code)
            self.assertTrue(common.compare_tail("rsi2_sample.output", res.get_output_lines()[-2:-1]))
            self.assertTrue(res.exit_ok())
开发者ID:363158858,项目名称:pyalgotrade-cn,代码行数:16,代码来源:doc_test.py


示例16: testMarketTiming

    def testMarketTiming(self):
        common.init_temp_path()
        files = []
        instruments = ["VTI", "VEU", "IEF", "VNQ", "DBC", "SPY"]
        for year in range(2007, 2013+1):
            for symbol in instruments:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        with common.CopyFiles(files, "data"):
            code = """import sys
sys.path.append('samples')
import market_timing
market_timing.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_tail("market_timing.output", lines[-10:-1]))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:17,代码来源:doc_test.py


示例17: testQuandl

    def testQuandl(self):
        files = []
        for year in range(2006, 2013):
            for symbol in ["GORO"]:
                fileName = "WIKI-%s-%d-quandl.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))
        files.append(os.path.join("samples", "data", "quandl_gold_2.csv"))

        with common.CopyFiles(files, "."):
            code = """import sys
sys.path.append('samples')
import quandl_sample
quandl_sample.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_head("quandl_sample.output", lines[0:10]))
            self.assertTrue(common.compare_tail("quandl_sample.output", lines[-10:-1]))
开发者ID:Greenwicher,项目名称:pyalgotrade,代码行数:17,代码来源:doc_test.py


示例18: testMarketTiming

    def testMarketTiming(self):
        common.init_temp_path()
        files = []
        instruments = ["MSFT", "ORCL", "IBM", "HPQ", "WMT", "UPS", "TGT", "CCL", "XOM", "CVX", "COP", "OXY", "BAC", "JPM", "WFC", "GS", "PG", "PEP", "CL", "KO"]
        for year in range(2005, 2013+1):
            for symbol in instruments:
                fileName = "%s-%d-yahoofinance.csv" % (symbol, year)
                files.append(os.path.join("samples", "data", fileName))

        with common.CopyFiles(files, "data"):
            code = """import sys
sys.path.append('samples')
import market_timing
market_timing.main(False)
"""
            lines = common.run_python_code(code).split("\n")
            self.assertTrue(common.compare_tail("market_timing.output", lines[-10:-1]))
开发者ID:anddam,项目名称:pyalgotrade,代码行数:17,代码来源:doc_test.py


示例19: testCSVFeed

    def testCSVFeed(self):
        with common.CopyFiles([os.path.join("samples", "data", "quandl_gold_2.csv")], "."):
            code = """import sys
sys.path.append('samples')
import csvfeed_1
"""
            res = common.run_python_code(code)
            lines = res.get_output_lines(True)
            self.assertEqual(
                common.head_file("csvfeed_1.output", 10),
                lines[0:10]
            )
            self.assertEqual(
                common.tail_file("csvfeed_1.output", 10),
                lines[-10:]
            )
            self.assertTrue(res.exit_ok())
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:17,代码来源:doc_test.py


示例20: testExample2

    def testExample2(self):
        with common.CopyFiles([os.path.join("testcases", "data", "30min-bitstampUSD-2.csv")], "30min-bitstampUSD.csv"):
            code = """import sys
sys.path.append('samples')
import bccharts_example_2
bccharts_example_2.main(False)
"""
            res = common.run_python_code(code)
            self.assertTrue(res.exit_ok(), res.get_output())
            self.assertEqual(
                res.get_output_lines()[0:10],
                common.head_file("bccharts_example_2.output", 10, path="testcases/data")
            )
            self.assertEqual(
                res.get_output_lines()[-10:],
                common.tail_file("bccharts_example_2.output", 10, path="testcases/data")
            )
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:17,代码来源:doc_test.py



注:本文中的testcases.common.run_python_code函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testcommon.getdata函数代码示例发布时间:2022-05-27
下一篇:
Python testcase.get_lib_path函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap