How to use require_tool method in Behave

Best Python code snippet using behave

Run Behave automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

java.configure

Source: java.configure Github

copy
1# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2# vim: set filetype=python:
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7
8# Java detection
9# ========================================================
10option('--with-java-bin-path', nargs=1,
11       help='Location of Java binaries (java, javac, jar)')
12
13@depends('--with-java-bin-path')
14@imports(_from='os', _import='environ')
15def java_search_paths(path):
16    if path:
17        # Look for javac and jar in the specified path.
18        return path
19    # With no path specified, look for javac and jar in $JAVA_HOME (if set)
20    # and $PATH.
21    if 'JAVA_HOME' in environ:
22        return [os.path.join(environ['JAVA_HOME'], 'bin'),
23                environ.get('PATH', '')]
24    return [environ.get('PATH')]
25
26# Finds the given java tool, failing with a custom error message if we can't
27# find it.
28@template
29def check_java_tool(tool):
30    check = check_prog(tool.upper(), (tool,), paths=java_search_paths,
31                       allow_missing=True)
32
33    @depends(check)
34    def require_tool(result):
35        if result is None:
36            die("The program %s was not found.  Set $JAVA_HOME to your Java "
37                "SDK directory or use '--with-java-bin-path={java-bin-dir}'"
38                % tool)
39        return result
40
41    return require_tool
42
43check_java_tool('java')
44check_java_tool('javah')
45check_java_tool('jar')
46check_java_tool('jarsigner')
47check_java_tool('keytool')
48javac = check_java_tool('javac')
49
50@depends(javac)
51@checking('for javac version')
52@imports('subprocess')
53def javac_version(javac):
54    try:
55        output = subprocess.check_output([javac, '-version'],
56                                         stderr=subprocess.STDOUT).rstrip()
57        version = Version(output.split(' ')[-1])
58        if version < '1.7':
59            die('javac 1.7 or higher is required (found %s)' % version)
60        return version
61    except subprocess.CalledProcessError as e:
62        die('Failed to get javac version: %s', e.output)
63
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Behave on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)