How to use test_run_coverage method in green

Best Python code snippet using green

test_run_coverage.py

Source:test_run_coverage.py Github

copy

Full Screen

1# Copyright 2020 Google LLC2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""Tests for run_crashes.py."""15# pylint: disable=no-self-use16import os17from unittest import mock18import glob19import pytest20from experiment.measurer import run_coverage21TEST_DATA_PATH = os.path.join(os.path.dirname(__file__), 'test_data',22 'test_run_coverage')23def _get_test_data_dir(directory):24 """Return the path of |TEST_DATA_PATH|/|directory|."""25 return os.path.join(TEST_DATA_PATH, directory)26def _make_crashes_dir(parent_path):27 """Makes a crashes dir in |parent_path| and returns it."""28 crashes_dir = os.path.join(str(parent_path), 'crashes')29 os.mkdir(crashes_dir)30 return crashes_dir31def _make_coverage_dir(parent_path):32 """Makes a profraw dir in |parent_path| and returns it."""33 coverage_dir = os.path.join(str(parent_path), 'coverage')34 os.mkdir(coverage_dir)35 return coverage_dir36def _assert_profraw_files(coverage_dir):37 """Ensure |coverage_dir| has profraw files."""38 pattern = coverage_dir39 if not pattern.endswith('/'):40 pattern += '/'41 pattern += '*.profraw'42 assert glob.glob(pattern)43@pytest.mark.skipif(not os.getenv('FUZZBENCH_TEST_INTEGRATION'),44 reason='Not running integration tests.')45class TestIntegrationRunCoverage:46 """Integration tests for run_coverage.py"""47 COVERAGE_BINARY_PATH = os.path.join(TEST_DATA_PATH, 'fuzz-target-clang-cov')48 def test_integration_do_coverage_run_crash(self, tmp_path):49 """Test that do_coverage_run returns crashing inputs."""50 units = _get_test_data_dir('crash-corpus')51 coverage_dir = _make_coverage_dir(tmp_path)52 profraw_file = os.path.join(coverage_dir, 'test_crash.profraw')53 crashes_dir = _make_crashes_dir(tmp_path)54 crashing_units = run_coverage.do_coverage_run(self.COVERAGE_BINARY_PATH,55 units, profraw_file,56 crashes_dir)57 # Ensure the crashing units are returned.58 assert crashing_units == ['86f7e437faa5a7fce15d1ddcb9eaeaea377667b8']59 _assert_profraw_files(coverage_dir)60 def test_integration_do_coverage_run_no_crash(self, tmp_path):61 """Test that do_coverage_run doesn't return crashing inputs when there62 are none."""63 units = _get_test_data_dir('corpus')64 coverage_dir = _make_coverage_dir(tmp_path)65 profraw_file = os.path.join(coverage_dir, 'test_no_crash.profraw')66 crashes_dir = _make_crashes_dir(tmp_path)67 crashing_units = run_coverage.do_coverage_run(self.COVERAGE_BINARY_PATH,68 units, profraw_file,69 crashes_dir)70 # Ensure no crashing unit is returned.71 assert not crashing_units72 _assert_profraw_files(coverage_dir)73 @mock.patch('common.logs.error')74 @mock.patch('experiment.measurer.run_coverage.MAX_TOTAL_TIME', 0)75 def test_integration_do_coverage_run_max_total_timeout(76 self, mocked_log_error, tmp_path):77 """Test that do_coverage_run respects max total time."""78 units = _get_test_data_dir('timeout-corpus')79 coverage_dir = _make_coverage_dir(tmp_path)80 profraw_file = os.path.join(coverage_dir, 'test_max_time.profraw')81 crashes_dir = _make_crashes_dir(tmp_path)82 crashing_units = run_coverage.do_coverage_run(self.COVERAGE_BINARY_PATH,83 units, profraw_file,84 crashes_dir)85 assert mocked_log_error.call_count86 # Ensure no crashing unit is returned....

Full Screen

Full Screen

test_run.py

Source:test_run.py Github

copy

Full Screen

...18 result = runner.invoke(cli, ['run', 'tests', '-r', 'unittest', '-t', 'tests'])19 assert result.exit_code == 020 result = runner.invoke(cli, ['run', 'tests', '-r', 'pytest', '-t', 'tests'])21 assert result.exit_code == 022 def test_run_coverage(self):23 runner = CliRunner()24 with runner.isolated_filesystem():25 create_project_structure('test_project', Path('test_project'), {'PROJECT_NAME': 'test_project',26 'MODULE_NAME': 'test_project'})27 os.chdir(Path.cwd() / 'test_project')28 shell('pip install -e .')29 result = runner.invoke(cli, ['run', 'coverage', '-r', 'unittest', '-s', 'test_project', '-t', 'tests'])30 assert result.exit_code == 031 result = runner.invoke(cli, ['run', 'coverage', '-r', 'pytest', '-s', 'test_project', '-t', 'tests'])32 assert result.exit_code == 033 @unittest.mock.patch('manati.run.click.launch')34 def test_run_docs(self, mock_launch):35 runner = CliRunner()36 with runner.isolated_filesystem():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run green automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful