How to use test_machine method in autotest

Best Python code snippet using autotest_python

tests.py

Source: tests.py Github

copy

Full Screen

1# copyright Merzlov Nikolay merzlovnik@mail.ru2import StackMachine as sm3import StackMachineCompilator as smc4import unittest5class Test(unittest.TestCase):6 def test_bool(self):7 test_machine = sm.StackMachine(8 [2, 3, "and"])9 test_machine.run()10 self.assertTrue(test_machine.top_of_stack)11 test_machine = sm.StackMachine(12 [2, 0, "or"])13 test_machine.run()14 self.assertTrue(test_machine.top_of_stack)15 test_machine = sm.StackMachine(16 [1, 1, "xor"])17 test_machine.run()18 self.assertFalse(test_machine.top_of_stack)19 test_machine = sm.StackMachine(20 [1, "not"])21 test_machine.run()22 self.assertFalse(test_machine.top_of_stack)23 def test_arithmetic(self):24 test_machine = sm.StackMachine(25 [2, 3, "+", 4, "*", 2, "/​", 6, "%", 1, "-", 3, "=="])26 test_machine.run()27 self.assertTrue(test_machine.top_of_stack)28 test_machine = sm.StackMachine(29 [2, 3, "+", 4, "*", 2, "/​", 6, "%", 1, "-", 5, ">"])30 test_machine.run()31 self.assertTrue(test_machine.top_of_stack)32 test_machine = sm.StackMachine(33 [-2, "abs"])34 test_machine.run()35 self.assertEqual(test_machine.top_of_stack, 2)36 test_machine = sm.StackMachine(37 [2, "negate"])38 test_machine.run()39 self.assertEqual(test_machine.top_of_stack, -2)40 def test_cast(self):41 test_machine = sm.StackMachine([2, "cast_str"])42 test_machine.run()43 self.assertEqual(test_machine.top_of_stack, "2")44 test_machine = sm.StackMachine(['"2"', "cast_int"])45 test_machine.run()46 self.assertEqual(test_machine.top_of_stack, 2)47 def test_drop(self):48 test_machine = sm.StackMachine([1, '"2"', "drop"])49 test_machine.run()50 self.assertEqual(test_machine.top_of_stack, 1)51 def test_dup(self):52 test_machine = sm.StackMachine([1, "dup", "+"])53 test_machine.run()54 self.assertEqual(test_machine.top_of_stack, 2)55 def test_if(self):56 test_machine = sm.StackMachine([1, '"False"', '"True"', "if"])57 test_machine.run()58 self.assertEqual(test_machine.top_of_stack, "True")59 test_machine = sm.StackMachine([0, '"False"', '"True"', "if"])60 test_machine.run()61 self.assertEqual(test_machine.top_of_stack, 'False')62 def test_jump(self):63 test_machine = sm.StackMachine([10, 7, "jmp", 0, "*", 0, "*", 1, "*"])64 test_machine.run()65 self.assertEqual(test_machine.top_of_stack, 10)66 def test_swap(self):67 test_machine = sm.StackMachine([1, 0, "swap", "-"])68 test_machine.run()69 self.assertEqual(test_machine.top_of_stack, -1)70 def test_call_return(self):71 test_machine = sm.StackMachine([4, "jmp", 50, "return", 2, "call", 2, "*"])72 test_machine.run()73 self.assertEqual(test_machine.top_of_stack, 100)74 def test_load_store(self):75 test_machine = sm.StackMachine([1, '"a"', "store", 0, '"a"', "load", "-"])76 test_machine.run()77 self.assertEqual(test_machine.top_of_stack, -1)78 def test_compilation(self):79 self.assertEqual(80 ['"Give me $a"', 41, 'call', '"a"', 'store', '"Give me $b"', 41, 'call', '"b"', 'store', '"Give me $c"', 41,81 'call',82 '"c"', 'store', '"Give me $x"', 41, 'call', '"x"', 'store', '"a"', 'load', '"x"', 'load', '*', '"b"',83 'load', '+',84 '"x"', 'load', '*', '"c"', 'load', '+', 'dup', 'println', 'stack', 'exit', 'dup', '*', 'return', 'print',85 'read',86 'cast_int', 'return'], smc.compile_file('example_code.txt')87 )88if __name__ == '__main__':...

Full Screen

Full Screen

test_commands.py

Source: test_commands.py Github

copy

Full Screen

1import unittest2import os3import docker4import machine5# machine name used for testing6TEST_MACHINE = os.environ.get("DOCKER_MACHINE", "python-docker-machine")7# invalid machine name8INVALID_MACHINE = TEST_MACHINE + "-invalid"9# temporary machine name10TEMPORARY_MACHINE = TEST_MACHINE + "-temporary"11class TestCommands(unittest.TestCase):12 @classmethod13 def setUpClass(cls):14 error = "can't find machine '%s', please create before running test suite." % TEST_MACHINE15 cls.machine = machine.machine.Machine()16 exists = cls.machine.exists(machine=TEST_MACHINE)17 assert exists, error18 @classmethod19 def tearDownClass(cls):20 try:21 cls.machine.rm(machine=INVALID_MACHINE)22 except RuntimeError:23 pass24 try:25 cls.machine.rm(machine=TEMPORARY_MACHINE)26 except RuntimeError:27 pass28 def setUp(self):29 if not self.machine.status(machine=TEST_MACHINE):30 self.machine.start(machine=TEST_MACHINE)31 def test_active(self):32 self.machine.active()33 def test_config(self):34 config = self.machine.config(machine=TEST_MACHINE)35 client = docker.Client(**config)36 self.assertTrue(client.ping())37 def test_config_invalid_machine(self):38 with self.assertRaises(RuntimeError):39 self.machine.config(machine=INVALID_MACHINE)40 @unittest.skip("disabled since it takes ages")41 def test_create_and_rm(self):42 self.machine.create(machine=TEMPORARY_MACHINE)43 self.machine.rm(machine=TEMPORARY_MACHINE)44 def test_env(self):45 self.machine.env(machine=TEST_MACHINE)46 def test_inspect(self):47 self.machine.inspect(machine=TEST_MACHINE)48 def test_ip(self):49 self.machine.ip(machine=TEST_MACHINE)50 def test_kill(self):51 self.machine.kill(machine=TEST_MACHINE)52 def test_ls(self):53 self.machine.ls()54 def test_provision(self):55 self.machine.provision(machine=TEST_MACHINE)56 def test_regenerate_certs(self):57 self.machine.regenerate_certs(machine=TEST_MACHINE)58 def test_restart(self):59 self.machine.restart(machine=TEST_MACHINE)60 def test_scp(self):61 # copy this file to the remote host62 source = os.path.realpath(__file__)63 destination = "%s:." % TEST_MACHINE64 self.machine.scp(source, destination)65 def test_start(self):66 self.machine.stop(machine=TEST_MACHINE)67 self.machine.start(machine=TEST_MACHINE)68 self.assertTrue(self.machine.status(machine=TEST_MACHINE))69 def test_status_when_up(self):70 self.assertTrue(self.machine.status(machine=TEST_MACHINE))71 def test_status_when_down(self):72 self.machine.stop(machine=TEST_MACHINE)73 self.assertFalse(self.machine.status(machine=TEST_MACHINE))74 def test_status_when_invalid_machine(self):75 with self.assertRaises(RuntimeError):76 self.machine.status(machine=INVALID_MACHINE)77 def test_stop(self):78 self.machine.stop(machine=TEST_MACHINE)79 self.assertFalse(self.machine.status(machine=TEST_MACHINE))80 def test_stop_when_stopped(self):81 self.machine.stop(machine=TEST_MACHINE)82 with self.assertRaises(RuntimeError):83 self.machine.stop(machine=TEST_MACHINE)84 def test_upgrade(self):85 self.machine.upgrade(machine=TEST_MACHINE)86 def test_url(self):87 self.machine.url(machine=TEST_MACHINE)88 def test_version(self):...

Full Screen

Full Screen

test_machines.py

Source: test_machines.py Github

copy

Full Screen

1import unittest2from api_cmds.machines import *3from api_cmds.reservations import count_reservations4class TestMachines(unittest.TestCase):5 def setUp(self) -> None:6 self.test_machine = add_and_verifies_new_machine()7 for i in range(10):8 add_and_verifies_new_machine()9 def test_add_one_machine(self):10 add_and_verifies_new_machine()11 def test_add_one_machine_and_get_details(self):12 machines_response = get_machine(self.test_machine["id"])13 self.assertEqual(machines_response["address"], self.test_machine["address"])14 self.assertEqual(machines_response["id"], self.test_machine["id"])15 def test_delete_one_machine(self):16 l_before = count_machines()17 created_machine = add_and_verifies_new_machine()18 self.assertTrue(remove_specific_machine(created_machine["id"]), "Service should return No Content")19 self.assertEqual(l_before, count_machines(), "Machine should be removed")20 def test_after_creation_machine_should_be_enabled(self):21 test_machine = get_machine(self.test_machine["id"])22 assert test_machine.get("enabled"), "Machine should be default enabled"23 def test_after_creation_machine_try_to_enable_twice(self):24 test_machine = get_machine(self.test_machine["id"])25 self.assertTrue(test_machine["enabled"], "Machine by the default should be enabled: True")26 self.assertTrue(enable(test_machine["id"]), "Machine should return Ok, even if is in this state")27 self.assertTrue(get_machine(test_machine["id"]).get("enabled"), "Machine should be enabled")28 def test_after_creation_machine_try_disable(self):29 test_machine = get_machine(self.test_machine["id"])30 self.assertTrue(test_machine["enabled"], "Machine by the default should be enabled: True")31 self.assertTrue(disable(test_machine["id"]), "Machine should return Ok, even if is in this state")32 self.assertFalse(get_machine(test_machine["id"]).get("enabled"), "Machine should be disabled")33 def test_add_two_machines_disable_one(self):34 second_machine = get_machine(add_example_machine()["id"])35 l_machines_before = count_machines()36 l_reservations_before = count_reservations()37 disable(second_machine["id"])38 self.assertEqual(l_machines_before, count_machines(), "Machines should be the same number as before")39 self.assertLess(count_reservations(), l_reservations_before, "One machine should not be visible at "40 "reservations")41 def tearDown(self) -> None:42 remove_all_machines()...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

Top 17 Resources To Learn Test Automation

Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

30 Top Automation Testing Tools In 2022

The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, & More

Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.

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