How to use run_test_suites method in autotest

Best Python code snippet using autotest_python

test_battleship.py

Source:test_battleship.py Github

copy

Full Screen

1# Copyright 2016 Intel Corporation2#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# ------------------------------------------------------------------------------15from __future__ import print_function16import unittest17import os18import random19import string20from sawtooth_battleship import battleship_cli21RUN_TEST_SUITES = True \22 if os.environ.get("RUN_TEST_SUITES", False) == "1" else False23@unittest.skipUnless(RUN_TEST_SUITES, "Must be run in a test suites")24class TestBattleshipCommands(unittest.TestCase):25 def _clean_data_and_key_files(self, user1, user2):26 home_dir = os.path.expanduser("~")27 key_dir = os.path.join(home_dir, ".sawtooth", "keys")28 data_dir = os.path.join(home_dir, ".sawtooth")29 user1_data = os.path.join(data_dir, "battleship-{}.data".format(user1))30 user2_data = os.path.join(data_dir, "battleship-{}.data".format(user2))31 user1_key = os.path.join(key_dir, "{}.priv".format(user1))32 user2_key = os.path.join(key_dir, "{}.priv".format(user2))33 user1_public_key = os.path.join(key_dir, "{}.addr".format(user1))34 user2_public_key = os.path.join(key_dir, "{}.addr".format(user2))35 files = [user1_data, user2_data, user1_key, user2_key,36 user1_public_key, user2_public_key]37 for f in files:38 try:39 os.remove(f)40 except OSError as ose:41 print("Could not remove file: {}".format(ose))42 def _call_battleship(self, args):43 battleship_cli.main('battleship', args)44 def test_all_commands(self):45 user1 = "".join([random.choice(string.ascii_letters)46 for _ in range(10)])47 user2 = "".join([random.choice(string.ascii_letters)48 for _ in range(10)])49 try:50 self._call_battleship(['init', '--username', user1])51 self._call_battleship(['create', 'game000', '--wait'])52 self._call_battleship(['join', 'game000', '--wait'])53 self._call_battleship(['init', '--username', user2])54 self._call_battleship(['create', 'game001',55 "--ships", 'BBB BBB SS SS DDDD', '--wait'])56 self._call_battleship(['join', 'game001', '--wait'])57 self._call_battleship(['join', 'game000', '--wait'])58 self._call_battleship(['init', '--username', user1])59 self._call_battleship(['join', 'game001', '--wait'])60 self._call_battleship(['show', 'game000'])61 self._call_battleship(['list'])62 self._call_battleship(['show', 'game001'])63 self._call_battleship(["fire", 'game000', 'A', '1', '--wait'])64 self._call_battleship(["show", 'game000'])65 self._call_battleship(['init', '--username', user2])66 self._call_battleship(['fire', 'game001', 'E', '5', '--wait'])67 self._call_battleship(['show', 'game001'])68 self._call_battleship(['show', 'game000'])69 self._call_battleship(['genstats', '--count', '10000',70 '--size', '10'])71 self._call_battleship(['init', '--username', user1])72 self._call_battleship(['list'])73 self._call_battleship(['show', 'game000'])74 self._call_battleship(['show', 'game001'])75 self._call_battleship(['fire', 'game001', 'A', '7', '--wait'])76 finally:...

Full Screen

Full Screen

run.py

Source:run.py Github

copy

Full Screen

2import sys3import test_suites4from testing_utils.globals import SANDBOXES_DIR, COLOR_GREEN, COLOR_RED, COLOR_END5from testing_utils.utils import clean_existing_tests, process_cli_flags6def run_test_suites():7 tests = test_suites.get_all_tests()8 nbr_of_tests = 09 succeeded_tests = 010 for test in tests:11 test_result = test()12 nbr_of_tests += 113 succeeded_tests += 1 if test_result else 014 if succeeded_tests == nbr_of_tests:15 print("\nRESULT : " + COLOR_GREEN + "{}/{}\n".format(succeeded_tests, nbr_of_tests) + COLOR_END)16 else:17 print(18 "\nRESULT : " + COLOR_RED + "{}/{}".format(succeeded_tests, nbr_of_tests) + COLOR_END +19 " (See '{}/' for outputs)\n".format(SANDBOXES_DIR)20 )21 return nbr_of_tests, succeeded_tests22if __name__ == '__main__':23 process_cli_flags(sys.argv)24 clean_existing_tests()25 test_results = run_test_suites()26 if test_results[0] != test_results[1]:27 sys.exit(1)...

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 autotest 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