How to use mock_venv method in tox

Best Python code snippet using tox_python

test_virtualenv_switcher.py

Source:test_virtualenv_switcher.py Github

copy

Full Screen

...22@pytest.fixture23def bindir(homedir):24 return homedir.mkdir('bin')25@pytest.fixture26def mock_venv(homedir):27 mock = homedir.mkdir('mock')28 venv = mock.mkdir('venv')29 bin = venv.mkdir('bin')30 activate = bin.join('activate')31 activate.write('foo')32 return venv33@pytest.fixture34def configfile(homedir):35 return homedir.join('.vs.conf')36@pytest.fixture37def getconfig(configfile):38 def loader():39 config = configparser.RawConfigParser()40 config.read(str(configfile))...

Full Screen

Full Screen

test_package.py

Source:test_package.py Github

copy

Full Screen

...45 with patch("homeassistant.util.package.os.environ.copy") as env_copy:46 env_copy.return_value = {}47 yield env_copy48@pytest.fixture49def mock_venv():50 """Mock homeassistant.util.package.is_virtual_env."""51 with patch("homeassistant.util.package.is_virtual_env") as mock:52 mock.return_value = True53 yield mock54def mock_async_subprocess():55 """Return an async Popen mock."""56 async_popen = MagicMock()57 async def communicate(input=None):58 """Communicate mock."""59 stdout = bytes("/deps_dir/lib_dir", "utf-8")60 return (stdout, None)61 async_popen.communicate = communicate62 return async_popen63def test_install(mock_sys, mock_popen, mock_env_copy, mock_venv):...

Full Screen

Full Screen

api_tests.py

Source:api_tests.py Github

copy

Full Screen

1from unittest import TestCase, mock2from resco import api3class ContextVerifier(object):4 def __enter__(self, *args, **kwargs):5 self.calls = []6 self.active = True7 def __exit__(self, *args):8 self.active = False9 def add_call(self, *args, **kwargs):10 if self.active:11 self.calls.append((args, kwargs))12 def attach(self, context, target):13 context.return_value = self14 target.side_effect = self.add_call15class TestRunCommand(TestCase):16 def setUp(self):17 self.patches = mock.patch.multiple('resco.api',18 local=mock.DEFAULT,19 put=mock.DEFAULT,20 run=mock.DEFAULT,21 cd=mock.DEFAULT,22 )23 self.mocks = self.patches.start()24 self.mock_venv = mock.MagicMock()25 def tearDown(self):26 mock.patch.stopall()27 def test_copies_files(self):28 api.run_command('{cmd}:{module}',29 'ANY_SCRIPT',30 self.mock_venv,31 'ANY_MODULE',32 'ANY_DIR')33 self.mocks['put'].assert_any_call('ANY_MODULE', 'ANY_DIR')34 def test_copies_scripts(self):35 api.run_command('{cmd}:{module}',36 'ANY_SCRIPT',37 self.mock_venv,38 'ANY_MODULE',39 'ANY_DIR')40 self.mocks['put'].assert_any_call('scripts', 'ANY_DIR')41 def test_runs_remotely(self):42 cv = ContextVerifier()43 cv.attach(self.mocks['cd'], self.mocks['run'])44 api.run_command('{cmd}:{module}',45 'scripts/ANY_SCRIPT',46 self.mock_venv,47 'ANY_MODULE',48 'ANY_DIR')49 self.mocks['run'].assert_called_once_with(50 'scripts/ANY_SCRIPT:ANY_MODULE')51 self.assertEqual(len(cv.calls), 1)52 @mock.patch('resco.api.run_unit_tests')53 def test_runs_unit_tests_first(self, mock_run_unit_tests):54 api.run_command('{cmd}:{module}',55 'ANY_SCRIPT',56 self.mock_venv,57 'ANY_MODULE',58 'ANY_DIR')59 mock_run_unit_tests.assert_called_once_with()60 def test_runs_in_venv(self):61 cv = ContextVerifier()62 cv.attach(self.mock_venv.activate, self.mocks['run'])63 api.run_command('{cmd}:{module}',64 'ANY_SCRIPT',65 self.mock_venv,66 'ANY_MODULE',67 'ANY_DIR')68 self.assertEqual(len(cv.calls), 1)69class TestRunScriptStartScript(TestCase):70 def setUp(self):71 self.mock_run_command = mock.patch('resco.api.run_command').start()72 self.mock_venv = mock.MagicMock()73 class MockEnv(object):74 venv = self.mock_venv75 module_name = 'ANY_MODULE'76 working_dir = 'ANY_DIR'77 self.mock_env = mock.patch('resco.api.env', MockEnv()).start()78 def tearDown(self):79 mock.patch.stopall()80 def test_run_script_calls_correctly(self):81 api.run_script('ANY_SCRIPT')82 self.mock_run_command.assert_called_once_with(83 '{cmd}',84 'PYTHONPATH=. python scripts/ANY_SCRIPT',85 self.mock_venv,86 'ANY_MODULE',87 'ANY_DIR',88 )89 def test_start_script_calls_correctly(self):90 api.start_script('ANY_SCRIPT')91 self.mock_run_command.assert_called_once_with(92 'tmux new-session -d -s ANY_MODULE "{cmd}"',93 'PYTHONPATH=. python scripts/ANY_SCRIPT',94 self.mock_venv,95 'ANY_MODULE',96 'ANY_DIR',97 )98 def test_start_script_accepts_jobname(self):99 api.start_script('ANY_SCRIPT', 'ANY_JOBNAME')100 self.mock_run_command.assert_called_once_with(101 'tmux new-session -d -s ANY_JOBNAME "{cmd}"',102 'PYTHONPATH=. python scripts/ANY_SCRIPT',103 self.mock_venv,104 'ANY_MODULE',105 'ANY_DIR',106 )107class TestCreateCommand(TestCase):108 def test_with_prefix(self):109 cmd = api.create_command('scripts/ANY_SCRIPT')110 self.assertEqual(cmd, 'PYTHONPATH=. python scripts/ANY_SCRIPT')111 def test_without_prefix(self):112 cmd = api.create_command('ANY_SCRIPT')113 self.assertEqual(cmd, 'PYTHONPATH=. python scripts/ANY_SCRIPT')114class TestFetchLs(TestCase):115 def setUp(self):116 self.mock_venv = mock.MagicMock()117 class MockEnv(object):118 venv = self.mock_venv119 module_name = 'ANY_MODULE'120 working_dir = 'ANY_DIR'121 self.mock_env = mock.patch('resco.api.env', MockEnv()).start()122 @mock.patch('resco.api.get')123 def test_fetch_fetches_to_same_location(self, mock_get):124 api.fetch('*.py')125 mock_get.assert_called_once_with(remote_path='target/*.py',...

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