当前位置: 首页>>代码示例>>Python>>正文


Python TestFileEnvironment.run方法代码示例

本文整理汇总了Python中scripttest.TestFileEnvironment.run方法的典型用法代码示例。如果您正苦于以下问题:Python TestFileEnvironment.run方法的具体用法?Python TestFileEnvironment.run怎么用?Python TestFileEnvironment.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scripttest.TestFileEnvironment的用法示例。


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

示例1: TestIntegration

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
class TestIntegration(unittest.TestCase):
    def setUp(self):
        self.env = TestFileEnvironment(test_path, template_path=template_path)

    def test_init(self):
        result = self.env.run("gpc", "init", expect_stderr=True)
        created_filenames = result.files_created.keys()
        self.assertTrue("log" in created_filenames)
        self.assertTrue("log/data" in created_filenames)
        self.assertTrue("log/schema.sql" in created_filenames)
        self.assertTrue("storage" in created_filenames)

    def test_make_target(self):
        self.env.run("gpc", "init", expect_stderr=True)
        self.env.writefile("gpc.yaml", frompath="simple.yaml")
        result = self.env.run("gpc", "make", "c", expect_stderr=True)
        created_filenames = list(result.files_created.keys())
        self.assertTrue("c" in created_filenames)
        created_filenames.remove("c")
        self.assertTrue(any([s.startswith("storage/") for s in created_filenames]))
        self.assertTrue(any([s.startswith("log/data/") for s in created_filenames]))

    def test_make_target_cached(self):
        call(["cp", "-r", template_path + "/.gpc", test_path])
        call(["cp", "-r", template_path + "/log", test_path])
        call(["cp", "-r", template_path + "/storage", test_path])
        self.env.writefile("gpc.yaml", frompath="simple.yaml")
        result = self.env.run("gpc", "make", "c", expect_stderr=True)
        created_filenames = result.files_created.keys()
        self.assertTrue("c" in created_filenames)
        self.assertTrue(len(created_filenames) == 1)
开发者ID:rasmuse,项目名称:graph-prov-test,代码行数:33,代码来源:test_integration.py

示例2: TestBasicCommands

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
class TestBasicCommands(TestCase):
    """Test basic command-line invoke of the program"""
    def setUp(self):
        self.env = TestFileEnvironment('./test-output')

    def test_default(self):
        res = self.env.run('../run.py', '-s', '1')
        assert 'Timeout' in res.stdout
        self.assertEqual(res.returncode, 0)

    def test_collect(self):
        res = self.env.run('../run.py', '-s', '1', '-c')
        assert 'Collecting' in res.stdout
        self.assertEqual(res.returncode, 0)

    def test_log(self):
        res = self.env.run('../run.py', '-s', '1', '--log', 'log.txt')
        assert 'Timeout' in res.stdout
        assert 'log.txt' in res.files_created
        self.assertEqual(res.returncode, 0)

    def test_segment(self):
        res = self.env.run('../run.py', '-s', '1', '--segment', '0.2')
        assert 'Timeout' in res.stdout
        self.assertEqual(res.returncode, 0)

    def tearDown(self):
        pass
开发者ID:kingjason,项目名称:soundmeter,代码行数:30,代码来源:tests.py

示例3: CLITest

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
class CLITest(unittest.TestCase):

    def setUp(self):
        import githook

        self.githook = githook
        self.githook.app.config['TESTING'] = True

        self.tempdir = tempfile.mkdtemp()
        self.env = TestFileEnvironment(
            os.path.join(self.tempdir,'test-output'),
            ignore_hidden=False)

    @unittest.skipIf(*is_travis)
    def test_no_config(self):
        result = self.env.run('bin/python %s' % os.path.join(here, "..", "__init__.py"),
            expect_error=True,
            cwd=os.path.join(here, '../', '../')
        )
        self.assertEqual(result.returncode, 1)
        self.assertEqual(result.stderr, u'CRITICAL:root:Configuration file not found. Please specify one.\n')

    # TODO This loops. :D Need another way of testing daemons.
    @unittest.skipIf(True, 'It loops')
    def test_ok_config(self):
        self.env.run('bin/python -m githook -c githook/tests/config/okconfig.ini',
            cwd=os.path.join(here, '../', '../')
        )
开发者ID:brodul,项目名称:githook,代码行数:30,代码来源:test.py

示例4: PhonebookTestCase

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
class PhonebookTestCase(unittest.TestCase):
    def setUp(self):
        self.env = TestFileEnvironment('./scratch')
        self.prefix = os.getcwd()
        
        # load phonebook fixture. Need to use separate name to prevent
        # overwriting actual file.
        with open('phonebook_fixture.txt') as f:
            with open('phonebook_fixture.pb', 'wb') as phonebook_fixture:
                for line in f:
                    phonebook_fixture.write(line)

    def tearDown(self):
        os.remove('phonebook_fixture.pb')

    # helper methods for ensuring things were/weren't added to files.
    def assert_not_added(self, entry_fields):
        result = self.env.run('cat %s/phonebook_fixture.pb' % self.prefix)
        for value in entry_fields:
            nose.tools.assert_not_in(value, result.stdout)

    def assert_added(self, entry_fields):
        result = self.env.run('cat %s/phonebook_fixture.pb' % self.prefix)
        for value in entry_fields:
            nose.tools.assert_in(value, result.stdout)
开发者ID:KatrinaE,项目名称:phonebook,代码行数:27,代码来源:validation_tests.py

示例5: get_env

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
    def get_env(self, check_help_version=True):
        #import tempfile
        #env = TestFileEnvironment(tempfile.mkdtemp(suffix='', prefix='test_' + script))
        env = TestFileEnvironment()

        # Use Agg backend for plots.
        #env.writefile("matplotlibrc", "backend: Agg")
        #with open(os.path.join(env.base_path, "matplotlibrc"), "wt") as fh:
        #    fh.write("backend: Agg\n")

        if check_help_version:
            # Start with --help. If this does not work...
            r = env.run(self.script, "--help", expect_stderr=self.expect_stderr)
            assert r.returncode == 0

            # Script must provide a version option
            r = env.run(self.script, "--version", expect_stderr=self.expect_stderr)
            assert r.returncode == 0
            print("stderr", r.stderr)
            print("stdout", r.stdout)
            verstr = r.stdout.strip()
            # deprecation warnings break --version
            #if not verstr: verstr = r.stdout.strip()  # py3k
            #assert str(verstr) == str(abilab.__version__)

        return env
开发者ID:gpetretto,项目名称:abipy,代码行数:28,代码来源:test_scripts.py

示例6: test_stop_service_minimal_docker_container

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def test_stop_service_minimal_docker_container():
    env = ScriptTestEnvironment()
    env.run('ansible-container', 'run', '--detached', cwd=project_dir('minimal_sleep'), expect_stderr=True)
    result = env.run('ansible-container', 'stop', 'minimal1',
                     cwd=project_dir('minimal_sleep'), expect_stderr=True)
    assert "Stopping ansible_minimal1_1 ... done" in result.stderr
    assert "Stopping ansible_minimal2_1 ... done" not in result.stderr
开发者ID:mukeshcopart,项目名称:ansible-container,代码行数:9,代码来源:test_slow.py

示例7: main

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def main():
    """ Main method
    Returns 0 on success, 1 on failure
    """
    start = timer()
    script = 'bin/csv2ofx --help'
    env = TestFileEnvironment('.scripttest')
    tmpfile = NamedTemporaryFile(dir=parent_dir, delete=False)
    tmpname = tmpfile.name

    tests = [
        (2, 'default.csv', 'default.qif', 'oq'),
        (3, 'default.csv', 'default_w_splits.qif', 'oqS Category'),
        (4, 'xero.csv', 'xero.qif', 'oqc Description -m xero'),
        (5, 'mint.csv', 'mint.qif', 'oqS Category -m mint'),
        (
            6, 'mint.csv', 'mint_alt.qif',
            'oqs20150613 -e20150614 -S Category -m mint'
        ),
        (7, 'default.csv', 'default.ofx', 'oe 20150908'),
        (8, 'default.csv', 'default_w_splits.ofx', 'oS Category'),
        (9, 'mint.csv', 'mint.ofx', 'oS Category -m mint'),
    ]

    try:
        env.run(script, cwd=parent_dir)
        print('\nScripttest #1: %s ... ok' % script)

        for test_num, example_filename, check_filename, opts in tests:
            example = p.join(example_dir, example_filename)
            check = p.join(check_dir, check_filename)
            checkfile = open(check)

            script = 'bin/csv2ofx -%s %s %s' % (opts, example, tmpname)
            env.run(script, cwd=parent_dir)
            args = [checkfile.readlines(), open(tmpname).readlines()]
            kwargs = {'fromfile': 'expected', 'tofile': 'got'}
            diffs = list(unified_diff(*args, **kwargs))

            if diffs:
                loc = ' '.join(script.split(' ')[:-1])
                msg = "ERROR from test #%i! Output:\n\t%s\n" % (test_num, loc)
                msg += "doesn't match hash of\n\t%s\n" % check
                sys.stderr.write(msg)
                sys.exit(''.join(diffs))
            else:
                short_script = 'csv2ofx -%s %s %s' % (
                    opts, example_filename, check_filename)

                print('Scripttest #%i: %s ... ok' % (test_num, short_script))
    except Exception as e:
        sys.exit(e)
    else:
        time = timer() - start
        print('%s' % '-' * 70)
        print('Ran %i scripttests in %0.3fs\n\nOK' % (test_num, time))
        sys.exit(0)
    finally:
        checkfile.close
        os.unlink(tmpname)
开发者ID:Drey,项目名称:csv2ofx,代码行数:62,代码来源:test.py

示例8: test_dojorun_dryrun

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
    def test_dojorun_dryrun(self):
        """Testing dojorun.py script in dry-run mode."""
        env = self.get_env()

        # Build new env to run the script in dry-run mode
        # Copy file from data to env.
        env = TestFileEnvironment(template_path=pdj_data.dirpath)
        env.writefile("Si.psp8", frompath="Si.psp8")
        env.writefile("Si.djrepo", frompath="Si.djrepo_empty")
        env.run(self.script, "Si.psp8", self.loglevel, self.verbose, "--dry-run")
开发者ID:ebousq,项目名称:pseudo_dojo,代码行数:12,代码来源:test_scripts.py

示例9: test_build_with_variables

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def test_build_with_variables():
    env = ScriptTestEnvironment()
    result = env.run('ansible-container', 'build', '--save-build-container', '--with-variables', 'foo=bar',
                     'bar=baz', cwd=project_dir('minimal'), expect_stderr=True)
    assert "Aborting on container exit" in result.stdout
    assert "Exported minimal-minimal with image ID " in result.stderr

    result = env.run('docker', 'inspect', '--format="{{ .Config.Env }}"', 'ansible_ansible-container_1',
                     expect_stderr=True)
    assert "foo=bar" in result.stdout
    assert "bar=baz" in result.stdout
开发者ID:containscafeine,项目名称:ansible-container,代码行数:13,代码来源:test_slow.py

示例10: test_build_with_volumes

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def test_build_with_volumes():
    env = ScriptTestEnvironment()
    volume_string = "{0}:{1}:{2}".format(os.getcwd(), '/projectdir', 'ro')
    result = env.run('ansible-container', 'build', '--save-build-container', '--with-volumes', volume_string,
                     cwd=project_dir('minimal'), expect_stderr=True)
    assert "Aborting on container exit" in result.stdout
    assert "Exported minimal-minimal with image ID " in result.stderr
    result = env.run('docker', 'inspect',
                     '--format="{{range .Mounts}}{{ .Source }}:{{ .Destination }}:{{ .Mode}} {{ end }}"',
                     'ansible_ansible-container_1', expect_stderr=True)
    volumes = result.stdout.split(' ')
    assert volume_string in volumes
开发者ID:containscafeine,项目名称:ansible-container,代码行数:14,代码来源:test_slow.py

示例11: test_shipit_kube

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def test_shipit_kube():
   env = ScriptTestEnvironment()
   # Should run shipit kube to success
   result = env.run('ansible-container', '--debug',  'shipit', 'kube', '--pull-from', 'https://index.docker.io/v1/ansible',
                    cwd=project_dir('postgres'), expect_error=True)
   assert result.returncode == 0
   assert "Role postgres created" in result.stderr
   # Should create a role
   result = env.run('ls ansible/roles', cwd=project_dir('postgres'))
   assert "postgres-kubernetes" in result.stdout
   # Should create a playbook
   result = env.run('ls ansible', cwd=project_dir('postgres'))
   assert "shipit-kubernetes.yml" in result.stdout
开发者ID:ansible,项目名称:ansible-container,代码行数:15,代码来源:test_slow.py

示例12: get_env

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
    def get_env(self):
        #import tempfile
        #env = TestFileEnvironment(tempfile.mkdtemp(suffix='', prefix='test_' + script))
        env = TestFileEnvironment()

        # Use Agg backend for plots.
        #env.writefile("matplotlibrc", "backend : Agg")

        # Start with --help. If this does not work...
        env.run(self.script, "--help")

        # Script must provide a version option
        #r = env.run(self.script, "--version", expect_stderr=True)
        #assert r.stderr.strip() == "%s version %s" % (os.path.basename(self.script), abilab.__version__)
        return env
开发者ID:ebousq,项目名称:pseudo_dojo,代码行数:17,代码来源:test_scripts.py

示例13: TestCommands

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
class TestCommands(TestCase):

    @classmethod
    def setUpClass(cls):
        create_run_script()

    def setUp(self):
        self.env = TestFileEnvironment('./test-output')

    def test_send_no_args(self):
        cmd = 'python ../run.py send'
        self.env.run(*shlex.split(cmd), expect_error=True)

    def test_send_alias_stdin(self):
        cmd = 'python ../run.py send -a "%s"' % (TEST_ALIAS)
        self.env.run(*shlex.split(cmd), stdin=b'Hi')
开发者ID:shichao-an,项目名称:adium-sh,代码行数:18,代码来源:test_adiumsh.py

示例14: test_no_command_shows_help

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def test_no_command_shows_help():
    env = ScriptTestEnvironment()
    result = env.run('ansible-container', expect_error=True)
    assert result.returncode == 2
    assert len(result.stdout) == 0
    assert "usage: ansible-container" in result.stderr
    assert "ansible-container: error:" in result.stderr
开发者ID:ansible,项目名称:ansible-container,代码行数:9,代码来源:test_fast.py

示例15: test_setting_ansible_container_envar

# 需要导入模块: from scripttest import TestFileEnvironment [as 别名]
# 或者: from scripttest.TestFileEnvironment import run [as 别名]
def test_setting_ansible_container_envar():
    env = ScriptTestEnvironment()
    result = env.run('ansible-container', '--debug', 'build',
                     cwd=project_dir('environment'), expect_stderr=True)
    assert "web MYVAR=foo ANSIBLE_CONTAINER=1" in result.stdout
    assert "db MYVAR=foo ANSIBLE_CONTAINER=1" in result.stdout
    assert "mw ANSIBLE_CONTAINER=1" in result.stdout
开发者ID:puredistortion,项目名称:ansible-container,代码行数:9,代码来源:test_slow.py


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