Best JavaScript code snippet using storybook-test-runner
testRemoveMembersFromGroups.py
Source:testRemoveMembersFromGroups.py
1"""2"""3# Created on 2016.04.174#5# Author: Giovanni Cannata6#7# Copyright 2016 - 2020 Giovanni Cannata8#9# This file is part of ldap3.10#11# ldap3 is free software: you can redistribute it and/or modify12# it under the terms of the GNU Lesser General Public License as published13# by the Free Software Foundation, either version 3 of the License, or14# (at your option) any later version.15#16# ldap3 is distributed in the hope that it will be useful,17# but WITHOUT ANY WARRANTY; without even the implied warranty of18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19# GNU Lesser General Public License for more details.20#21# You should have received a copy of the GNU Lesser General Public License22# along with ldap3 in the COPYING and COPYING.LESSER files.23# If not, see <http://www.gnu.org/licenses/>.24import unittest25from test.config import test_base, add_user, add_group, get_connection, drop_connection, random_id, test_server_type, get_response_values26testcase_id = ''27class Test(unittest.TestCase):28 def setUp(self):29 global testcase_id30 testcase_id = random_id()31 self.connection = get_connection()32 self.delete_at_teardown = []33 def tearDown(self):34 drop_connection(self.connection, self.delete_at_teardown)35 self.assertFalse(self.connection.bound)36 def test_remove_member_from_group(self):37 if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:38 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-1'))39 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-1'))40 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-1b', [self.delete_at_teardown[0]]))41 self.connection.extend.novell.add_members_to_groups(self.delete_at_teardown[0][0],42 [self.delete_at_teardown[1][0],43 self.delete_at_teardown[2][0]],44 fix=True,45 transaction=False)46 # verifies user in group-147 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)48 if response:49 self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))50 self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))51 else:52 self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found')53 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)54 if response:55 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))56 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))57 else:58 self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found')59 # verifies user in group-1b60 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)61 if response:62 self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))63 self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))64 else:65 self.assertFalse(True, self.delete_at_teardown[2][0] + ' not found')66 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[2][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)67 if response:68 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))69 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))70 else:71 self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found')72 self.connection.extend.novell.remove_members_from_groups(self.delete_at_teardown[0][0],73 self.delete_at_teardown[1][0],74 fix=False,75 transaction=False)76 # verifies users not in group-177 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)78 if response:79 self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))80 self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))81 else:82 self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found')83 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)84 if response:85 self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))86 self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))87 else:88 self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found')89 # verifies user still in group-1b90 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)91 if response:92 self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))93 self.assertTrue(self.delete_at_teardown[2][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))94 else:95 self.assertFalse(True, self.delete_at_teardown[2][0] + ' not found')96 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[2][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)97 if response:98 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))99 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))100 else:101 self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found')102 def test_remove_members_from_groups(self):103 if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:104 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-2'))105 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-3'))106 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-4'))107 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-2', self.delete_at_teardown))108 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-3'))109 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-4'))110 self.connection.extend.novell.add_members_to_groups([self.delete_at_teardown[0][0],111 self.delete_at_teardown[1][0],112 self.delete_at_teardown[2][0]],113 [self.delete_at_teardown[3][0],114 self.delete_at_teardown[4][0],115 self.delete_at_teardown[5][0]],116 fix=True,117 transaction=False118 )119 for i in range(0, 2):120 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)121 if response:122 for j in range(3, 5):123 self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))124 self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))125 else:126 self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found')127 for j in range(3, 5):128 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)129 if response:130 for i in range(0, 2):131 self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))132 self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))133 else:134 self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found')135 self.connection.extend.novell.remove_members_from_groups([self.delete_at_teardown[0][0],136 self.delete_at_teardown[1][0],137 self.delete_at_teardown[2][0]],138 [self.delete_at_teardown[3][0],139 self.delete_at_teardown[4][0],140 self.delete_at_teardown[5][0]],141 fix=True,142 transaction=False143 )144 for i in range(0, 2):145 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)146 if response:147 for j in range(3, 5):148 self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))149 self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))150 else:151 self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found')152 for j in range(3, 5):153 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)154 if response:155 for i in range(0, 2):156 self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))157 self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))158 else:159 self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found')160 def test_remove_member_from_group_transactional(self):161 if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:162 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-5'))163 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-5', self.delete_at_teardown))164 self.connection.extend.novell.add_members_to_groups(self.delete_at_teardown[0][0],165 self.delete_at_teardown[1][0],166 fix=True,167 transaction=True)168 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)169 if response:170 self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))171 self.assertTrue(self.delete_at_teardown[1][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))172 else:173 self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found')174 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)175 if response:176 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))177 self.assertTrue(self.delete_at_teardown[0][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))178 else:179 self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found')180 self.connection.extend.novell.remove_members_from_groups(self.delete_at_teardown[0][0],181 self.delete_at_teardown[1][0],182 fix=False,183 transaction=False)184 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[0][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)185 if response:186 self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))187 self.assertTrue(self.delete_at_teardown[1][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))188 else:189 self.assertFalse(True, self.delete_at_teardown[1][0] + ' not found')190 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[1][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)191 if response:192 self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))193 self.assertTrue(self.delete_at_teardown[0][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))194 else:195 self.assertFalse(True, self.delete_at_teardown[0][0] + ' not found')196 def test_remove_members_from_groups_transactional(self):197 if test_server_type == 'EDIR' and not self.connection.strategy.pooled and not self.connection.strategy.no_real_dsa:198 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-6'))199 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-7'))200 self.delete_at_teardown.append(add_user(self.connection, testcase_id, 'user-8'))201 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-6', self.delete_at_teardown)) # this group has members but other attributes are not set202 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-7'))203 self.delete_at_teardown.append(add_group(self.connection, testcase_id, 'group-8'))204 self.connection.extend.novell.add_members_to_groups([self.delete_at_teardown[0][0],205 self.delete_at_teardown[1][0],206 self.delete_at_teardown[2][0]],207 [self.delete_at_teardown[3][0],208 self.delete_at_teardown[4][0],209 self.delete_at_teardown[5][0]],210 fix=True,211 transaction=True212 )213 for i in range(0, 2):214 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)215 if response:216 for j in range(3, 5):217 self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))218 self.assertTrue(self.delete_at_teardown[j][0] in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))219 else:220 self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found')221 for j in range(3, 5):222 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)223 if response:224 for i in range(0, 2):225 self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))226 self.assertTrue(self.delete_at_teardown[i][0] in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))227 else:228 self.assertFalse(True, self.delete_at_teardown[j][0] + ' not found')229 self.connection.extend.novell.remove_members_from_groups([self.delete_at_teardown[0][0],230 self.delete_at_teardown[1][0],231 self.delete_at_teardown[2][0]],232 [self.delete_at_teardown[3][0],233 self.delete_at_teardown[4][0],234 self.delete_at_teardown[5][0]],235 fix=True,236 transaction=False237 )238 for i in range(0, 2):239 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[i][0], '(objectclass=*)', attributes=['securityEquals', 'groupMembership']), self.connection)240 if response:241 for j in range(3, 5):242 self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['securityEquals'] if 'securityEquals' in response[0]['attributes'] else []))243 self.assertTrue(self.delete_at_teardown[j][0] not in (response[0]['attributes']['groupMembership'] if 'groupMembership' in response[0]['attributes'] else []))244 else:245 self.assertFalse(True, self.delete_at_teardown[i][0] + ' not found')246 for j in range(3, 5):247 status, result, response, request = get_response_values(self.connection.search(self.delete_at_teardown[j][0], '(objectclass=*)', attributes=['member', 'equivalentToMe']), self.connection)248 if response:249 for i in range(0, 2):250 self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['member'] if 'member' in response[0]['attributes'] else []))251 self.assertTrue(self.delete_at_teardown[i][0] not in (response[0]['attributes']['equivalentToMe'] if 'equivalentToMe' in response[0]['attributes'] else []))252 else:...
test_suite.py
Source:test_suite.py
...99 del self.state100 def test_setup_none(self):101 self.assertTrue(self.state.setup(None))102 def test_teardown_no_prior_setup_does_not_raise(self):103 self.state.teardown()104 @contextmanager105 def _temporary_module(self, klass, module):106 module_name = 'haas_test_module_{0}'.format(next(self._name_count))107 self.assertNotIn(module_name, sys.modules)108 sys.modules[module_name] = module109 old_module = klass.__module__110 klass.__module__ = module_name111 try:112 yield113 finally:114 klass.__module__ = old_module115 del sys.modules[module_name]116 def _prepare_test(self, klass, module_factory, setup_raise,117 teardown_raise):118 klass.setup_raise = setup_raise119 klass.teardown_raise = teardown_raise120 test = klass()121 if module_factory is not None:122 module = module_factory(123 setup_raise=setup_raise,124 teardown_raise=teardown_raise,125 )126 else:127 module = None128 return test, module129 @contextmanager130 def _run_test_context(self, klass, module_factory, setup_raise,131 teardown_raise, class_setup, class_teardown,132 module_setup, module_teardown):133 test, module = self._prepare_test(134 klass, module_factory, setup_raise, teardown_raise)135 with self._temporary_module(klass, module):136 self.assertEqual(self.state.setup(test), not setup_raise)137 self.assertEqual(klass.setup, class_setup)138 self.assertFalse(klass.teardown)139 if module is not None:140 self.assertEqual(module.setup, module_setup)141 self.assertFalse(module.teardown)142 yield test143 self.state.teardown()144 self.assertEqual(klass.setup, class_setup)145 self.assertEqual(klass.teardown, class_teardown)146 if module is not None:147 self.assertEqual(module.setup, module_setup)148 self.assertEqual(module.teardown, module_teardown)149 def _run_test(self, klass, module_factory, setup_raise, teardown_raise,150 class_setup, class_teardown, module_setup, module_teardown):151 with self._run_test_context(152 klass, module_factory, setup_raise, teardown_raise,153 class_setup, class_teardown, module_setup, module_teardown):154 pass155 def test_call_setup_without_setup_or_teardown(self):156 self._run_test(157 klass=MockTestCase,158 module_factory=MockModule,159 setup_raise=False,160 teardown_raise=False,161 class_setup=False,162 class_teardown=False,163 module_setup=False,164 module_teardown=False,165 )166 def test_setup_skip(self):167 MockTestCaseSetupTeardown.__unittest_skip__ = True168 self._run_test(169 klass=MockTestCaseSetupTeardown,170 module_factory=MockModule,171 setup_raise=False,172 teardown_raise=False,173 class_setup=False,174 class_teardown=False,175 module_setup=False,176 module_teardown=False,177 )178 def test_setup_case_setup(self):179 self._run_test(180 klass=MockTestCaseSetup,181 module_factory=MockModule,182 setup_raise=False,183 teardown_raise=False,184 class_setup=True,185 class_teardown=False,186 module_setup=False,187 module_teardown=False,188 )189 def test_setup_case_teardown(self):190 self._run_test(191 klass=MockTestCaseTeardown,192 module_factory=MockModule,193 setup_raise=False,194 teardown_raise=False,195 class_setup=False,196 class_teardown=True,197 module_setup=False,198 module_teardown=False,199 )200 def test_setup_case_setup_and_teardown(self):201 self._run_test(202 klass=MockTestCaseSetupTeardown,203 module_factory=MockModule,204 setup_raise=False,205 teardown_raise=False,206 class_setup=True,207 class_teardown=True,208 module_setup=False,209 module_teardown=False,210 )211 def test_setup_case_setup_raises_and_teardown(self):212 self._run_test(213 klass=MockTestCaseSetupTeardown,214 module_factory=MockModule,215 setup_raise=True,216 teardown_raise=False,217 class_setup=True,218 class_teardown=False,219 module_setup=False,220 module_teardown=False,221 )222 def test_setup_case_setup_and_teardown_raises(self):223 self._run_test(224 klass=MockTestCaseSetupTeardown,225 module_factory=MockModule,226 setup_raise=False,227 teardown_raise=True,228 class_setup=True,229 class_teardown=True,230 module_setup=False,231 module_teardown=False,232 )233 def test_setup_module_setup(self):234 self._run_test(235 klass=MockTestCase,236 module_factory=MockModuleSetup,237 setup_raise=False,238 teardown_raise=False,239 class_setup=False,240 class_teardown=False,241 module_setup=True,242 module_teardown=False,243 )244 def test_setup_module_teardown(self):245 self._run_test(246 klass=MockTestCase,247 module_factory=MockModuleTeardown,248 setup_raise=False,249 teardown_raise=False,250 class_setup=False,251 class_teardown=False,252 module_setup=False,253 module_teardown=True,254 )255 def test_setup_module_setup_and_teardown(self):256 self._run_test(257 klass=MockTestCase,258 module_factory=MockModuleSetupTeardown,259 setup_raise=False,260 teardown_raise=False,261 class_setup=False,262 class_teardown=False,263 module_setup=True,264 module_teardown=True,265 )266 def test_setup_module_setup_raises_and_teardown(self):267 self._run_test(268 klass=MockTestCase,269 module_factory=MockModuleSetupTeardown,270 setup_raise=True,271 teardown_raise=False,272 class_setup=False,273 class_teardown=False,274 module_setup=True,275 module_teardown=False,276 )277 def test_setup_module_setup_and_teardown_raises(self):278 self._run_test(279 klass=MockTestCase,280 module_factory=MockModuleSetupTeardown,...
test_file.py
Source:test_file.py
1# This file is part of Exdir, the Experimental Directory Structure.2#3# Copyright 2017 Simen Tennøe4#5# License: MIT, see "LICENSE" file for the full license terms.6#7# This file contains code from h5py, a Python interface to the HDF5 library,8# licensed under a standard 3-clause BSD license9# with copyright Andrew Collette and contributors.10# See http://www.h5py.org and the "3rdparty/h5py-LICENSE" file for details.11import pytest12import os13import pathlib14from exdir.core import File, Group15from exdir.core.exdir_object import _create_object_directory, is_nonraw_object_directory, DATASET_TYPENAME, FILE_TYPENAME16import exdir.core.filename_validation as fv17import numpy as np18from conftest import remove19def test_file_init(setup_teardown_folder):20 no_exdir = setup_teardown_folder[0] / "no_exdir"21 f = File(no_exdir, mode="w")22 f.close()23 assert is_nonraw_object_directory(no_exdir.with_suffix(".exdir"))24 remove(setup_teardown_folder[1])25 f = File(setup_teardown_folder[1], mode="w")26 f.close()27 assert is_nonraw_object_directory(setup_teardown_folder[1])28 remove(setup_teardown_folder[1])29 f = File(setup_teardown_folder[1], mode="a")30 f.close()31 assert is_nonraw_object_directory(setup_teardown_folder[1])32 remove(setup_teardown_folder[1])33 f = File(setup_teardown_folder[1], mode="a")34 f.close()35 assert is_nonraw_object_directory(setup_teardown_folder[1])36 remove(setup_teardown_folder[1])37 setup_teardown_folder[1].mkdir(parents=True)38 with pytest.raises(FileExistsError):39 f = File(setup_teardown_folder[1], mode="w")40 remove(setup_teardown_folder[1])41 _create_object_directory(pathlib.Path(setup_teardown_folder[1]), DATASET_TYPENAME)42 with pytest.raises(FileExistsError):43 f = File(setup_teardown_folder[1], mode="w")44 remove(setup_teardown_folder[1])45 with pytest.raises(IOError):46 f = File(setup_teardown_folder[1], mode="r")47 with pytest.raises(IOError):48 f = File(setup_teardown_folder[1], mode="r+")49 _create_object_directory(pathlib.Path(setup_teardown_folder[1]), FILE_TYPENAME)50 with pytest.raises(FileExistsError):51 f = File(setup_teardown_folder[1], mode="w")52 remove(setup_teardown_folder[1])53 _create_object_directory(pathlib.Path(setup_teardown_folder[1]), FILE_TYPENAME)54 f = File(setup_teardown_folder[1], mode="w", allow_remove=True)55 remove(setup_teardown_folder[1])56 _create_object_directory(pathlib.Path(setup_teardown_folder[1]), FILE_TYPENAME)57 with pytest.raises(IOError):58 f = File(setup_teardown_folder[1], mode="w-")59 with pytest.raises(IOError):60 f = File(setup_teardown_folder[1], mode="x")61 with pytest.raises(ValueError):62 f = File(setup_teardown_folder[1], mode="not existing")63def test_create(setup_teardown_folder):64 """Mode 'w' opens file in overwrite mode."""65 f = File(setup_teardown_folder[1], 'w')66 assert f67 f.create_group('foo')68 f.close()69 f = File(setup_teardown_folder[1], 'w', allow_remove=True)70 assert 'foo' not in f71 f.close()72 with pytest.raises(FileExistsError):73 f = File(setup_teardown_folder[1], 'w')74def test_create_exclusive(setup_teardown_folder):75 """Mode 'w-' opens file in exclusive mode."""76 f = File(setup_teardown_folder[1], 'w-')77 assert f78 f.close()79 with pytest.raises(IOError):80 File(setup_teardown_folder[1], 'w-')81def test_append(setup_teardown_folder):82 """Mode 'a' opens file in append/readwrite mode, creating if necessary."""83 f = File(setup_teardown_folder[1], 'a')84 assert f85 f.create_group('foo')86 assert 'foo' in f87 f = File(setup_teardown_folder[1], 'a')88 assert 'foo' in f89 f.create_group('bar')90 assert 'bar' in f91def test_readonly(setup_teardown_folder):92 """Mode 'r' opens file in readonly mode."""93 f = File(setup_teardown_folder[1], 'w')94 f.close()95 # TODO comment in when close is implemented96 # assert not f97 f = File(setup_teardown_folder[1], 'r')98 assert f99 with pytest.raises(IOError):100 f.create_group('foo')101 f.create_dataset("bar", (2))102 f.close()103def test_readwrite(setup_teardown_folder):104 """Mode 'r+' opens existing file in readwrite mode."""105 f = File(setup_teardown_folder[1], 'w')106 f.create_group('foo')107 f.close()108 f = File(setup_teardown_folder[1], 'r+')109 assert 'foo' in f110 f.create_group('bar')111 assert 'bar' in f112 f.close()113def test_nonexistent_file(setup_teardown_folder):114 """Modes 'r' and 'r+' do not create files."""115 with pytest.raises(IOError):116 File(setup_teardown_folder[1], 'r')117 with pytest.raises(IOError):118 File(setup_teardown_folder[1], 'r+')119def test_invalid_mode(setup_teardown_folder):120 """Invalid modes raise ValueError."""121 with pytest.raises(ValueError):122 File(setup_teardown_folder[1], 'Error mode')123def test_file_close(setup_teardown_folder):124 """Closing a file."""125 f = File(setup_teardown_folder[1], mode="w")126 f.close()127def test_validate_name_thorough(setup_teardown_folder):128 """Test naming rule thorough."""129 f = File(setup_teardown_folder[0] / "test.exdir", validate_name=fv.thorough)130 f.close()131 with pytest.raises(FileExistsError):132 File(setup_teardown_folder[0] / "Test.exdir", validate_name=fv.thorough)133 with pytest.raises(NameError):134 File(setup_teardown_folder[0] / "tes#.exdir", validate_name=fv.thorough)135def test_validate_name_strict(setup_teardown_folder):136 """Test naming rule strict."""137 f = File(setup_teardown_folder[1], validate_name=fv.strict)138 f.close()139 with pytest.raises(NameError):140 File(setup_teardown_folder[1].with_suffix(".exdirA"), validate_name=fv.strict)141def test_validate_name_error(setup_teardown_folder):142 """Test naming rule with error."""143 with pytest.raises(ValueError):144 File(setup_teardown_folder[1], validate_name='Error rule')145def test_validate_name_none(setup_teardown_folder):146 """Test naming rule with error."""147 File(setup_teardown_folder[1].with_name("test&().exdir"), validate_name=fv.none)148def test_opening_with_different_validate_name(setup_teardown_folder):149 """Test opening with wrong naming rule."""150 f = File(setup_teardown_folder[1], "w", validate_name=fv.none)151 f.create_group("AAA")152 f.close()153 # TODO changing name validation should result in warning/error154 f = File(setup_teardown_folder[1], "a", validate_name=fv.thorough)155 with pytest.raises(FileExistsError):156 f.create_group("aaa")157 f.close()158def test_contains(setup_teardown_file):159 """Root group (by itself) is contained."""160 f = setup_teardown_file[3]161 f.create_group("test")162 assert "/" in f163 assert "/test" in f164def test_create_group(setup_teardown_file):165 """Root group (by itself) is contained."""166 f = setup_teardown_file[3]167 grp = f.create_group("/test")168 assert isinstance(grp, Group)169def test_require_group(setup_teardown_file):170 """Root group (by itself) is contained."""171 f = setup_teardown_file[3]172 grp = f.require_group("/foo")173 assert isinstance(grp, Group)174def test_open(setup_teardown_file):175 """thorough obj[name] opening."""176 f = setup_teardown_file[3]177 grp = f.create_group("foo")178 grp2 = f["foo"]179 grp3 = f["/foo"]180 f = f["/"]181 assert grp == grp2182 assert grp2 == grp3183 assert f == f184def test_open_mode(setup_teardown_folder):185 # must exist186 for mode in ["r+", "r"]:187 with pytest.raises(IOError):188 f = File(setup_teardown_folder[1], mode)189 # create if not exist190 for mode in ["a", "w", "w-"]:191 remove(setup_teardown_folder[1])192 f = File(setup_teardown_folder[1], mode)193 f.require_dataset('dset', np.arange(10))194 f.attrs['can_overwrite'] = 42195 f.attrs['can_overwrite'] = 14196 f.require_group('mygroup')197 remove(setup_teardown_folder[1])198 f = File(setup_teardown_folder[1], 'w')199 f.close() # dummy close200 # read write if exist201 f = File(setup_teardown_folder[1], "r+")202 f.require_group('mygroup')203 f.require_dataset('dset', np.arange(10))204 f.attrs['can_overwrite'] = 42205 f.attrs['can_overwrite'] = 14206 # read only, can not write207 f = File(setup_teardown_folder[1], 'r')208 with pytest.raises(IOError):209 f.require_dataset('dset', np.arange(10))210 f.attrs['can_not_write'] = 42211 f.create_group('mygroup')212def test_open_two_attrs(setup_teardown_file):213 f = setup_teardown_file[3]214 f.attrs['can_overwrite'] = 42215 f.attrs['another_atribute'] = 14216# TODO uncomment when enter and exit has been implemented217# # Feature: File objects can be used as context managers218# def test_context_manager(setup_teardown_folder):219# """File objects can be used in with statements."""220# no_exdir = pytest.TESTPATH / "no_exdir"221# with File(no_exdir, mode="w") as f:222# assert f...
test_statuses.py
Source:test_statuses.py
1import os2import sys3from avocado import Test, skip4class SkipSetup(Test):5 @skip("from setUp()")6 def setUp(self):7 self.log.info('setup pre')8 self.log.info('setup post')9 def test(self):10 self.log.info('test pre')11 self.log.info('test post')12 def tearDown(self):13 self.log.info('teardown pre')14 self.log.info('teardown status: %s', self.status)15 self.log.info('teardown post')16class SkipTest(Test):17 def setUp(self):18 self.log.info('setup pre')19 self.log.info('setup post')20 @skip("from test()")21 def test(self):22 self.log.info('test pre')23 self.log.info('test post')24 def tearDown(self):25 self.log.info('teardown pre')26 self.log.info('teardown status: %s', self.status)27 self.log.info('teardown post')28class SkipTeardown(Test):29 def setUp(self):30 self.log.info('setup pre')31 self.log.info('setup post')32 def test(self):33 self.log.info('test pre')34 self.log.info('test post')35 @skip("from tearDown()")36 def tearDown(self):37 self.log.info('teardown pre')38 self.log.info('teardown status: %s', self.status)39 self.log.info('teardown post')40class CancelSetup(Test):41 def setUp(self):42 self.log.info('setup pre')43 self.cancel()44 self.log.info('setup post')45 def test(self):46 self.log.info('test pre')47 self.log.info('test post')48 def tearDown(self):49 self.log.info('teardown pre')50 self.log.info('teardown status: %s', self.status)51 self.log.info('teardown post')52class CancelTest(Test):53 def setUp(self):54 self.log.info('setup pre')55 self.log.info('setup post')56 def test(self):57 self.log.info('test pre')58 self.cancel()59 self.log.info('test post')60 def tearDown(self):61 self.log.info('teardown pre')62 self.log.info('teardown status: %s', self.status)63 self.log.info('teardown post')64class CancelTeardown(Test):65 def setUp(self):66 self.log.info('setup pre')67 self.log.info('setup post')68 def test(self):69 self.log.info('test pre')70 self.log.info('test post')71 def tearDown(self):72 self.log.info('teardown pre')73 self.log.info('teardown status: %s', self.status)74 self.cancel()75 self.log.info('teardown post')76class FailSetup(Test):77 def setUp(self):78 self.log.info('setup pre')79 self.fail()80 self.log.info('setup post')81 def test(self):82 self.log.info('test pre')83 self.log.info('test post')84 def tearDown(self):85 self.log.info('teardown pre')86 self.log.info('teardown status: %s', self.status)87 self.log.info('teardown post')88class FailTest(Test):89 def setUp(self):90 self.log.info('setup pre')91 self.log.info('setup post')92 def test(self):93 self.log.info('test pre')94 self.fail()95 self.log.info('test post')96 def tearDown(self):97 self.log.info('teardown pre')98 self.log.info('teardown status: %s', self.status)99 self.log.info('teardown post')100class FailTeardown(Test):101 def setUp(self):102 self.log.info('setup pre')103 self.log.info('setup post')104 def test(self):105 self.log.info('test pre')106 self.log.info('test post')107 def tearDown(self):108 self.log.info('teardown pre')109 self.log.info('teardown status: %s', self.status)110 self.fail()111 self.log.info('teardown post')112class WarnSetup(Test):113 def setUp(self):114 self.log.info('setup pre')115 self.log.warn('')116 self.log.info('setup post')117 def test(self):118 self.log.info('test pre')119 self.log.info('test post')120 def tearDown(self):121 self.log.info('teardown pre')122 self.log.info('teardown status: %s', self.status)123 self.log.info('teardown post')124class WarnTest(Test):125 def setUp(self):126 self.log.info('setup pre')127 self.log.info('setup post')128 def test(self):129 self.log.info('test pre')130 self.log.warn('')131 self.log.info('test post')132 def tearDown(self):133 self.log.info('teardown pre')134 self.log.info('teardown status: %s', self.status)135 self.log.info('teardown post')136class WarnTeardown(Test):137 def setUp(self):138 self.log.info('setup pre')139 self.log.info('setup post')140 def test(self):141 self.log.info('test pre')142 self.log.info('test post')143 def tearDown(self):144 self.log.info('teardown pre')145 self.log.info('teardown status: %s', self.status)146 self.log.warn('')147 self.log.info('teardown post')148class ExitSetup(Test):149 def setUp(self):150 self.log.info('setup pre')151 sys.exit(-1)152 self.log.info('setup post')153 def test(self):154 self.log.info('test pre')155 self.log.info('test post')156 def tearDown(self):157 self.log.info('teardown pre')158 self.log.info('teardown status: %s', self.status)159 self.log.info('teardown post')160class ExitTest(Test):161 def setUp(self):162 self.log.info('setup pre')163 self.log.info('setup post')164 def test(self):165 self.log.info('test pre')166 sys.exit(-1)167 self.log.info('test post')168 def tearDown(self):169 self.log.info('teardown pre')170 self.log.info('teardown status: %s', self.status)171 self.log.info('teardown post')172class ExitTeardown(Test):173 def setUp(self):174 self.log.info('setup pre')175 self.log.info('setup post')176 def test(self):177 self.log.info('test pre')178 self.log.info('test post')179 def tearDown(self):180 self.log.info('teardown pre')181 self.log.info('teardown status: %s', self.status)182 sys.exit(-1)183 self.log.info('teardown post')184class ExceptionSetup(Test):185 def setUp(self):186 self.log.info('setup pre')187 raise ValueError188 # pylint: disable=W0101189 self.log.info('setup post')190 def test(self):191 self.log.info('test pre')192 self.log.info('test post')193 def tearDown(self):194 self.log.info('teardown pre')195 self.log.info('teardown status: %s', self.status)196 self.log.info('teardown post')197class ExceptionTest(Test):198 def setUp(self):199 self.log.info('setup pre')200 self.log.info('setup post')201 def test(self):202 self.log.info('test pre')203 raise ValueError204 # pylint: disable=W0101205 self.log.info('test post')206 def tearDown(self):207 self.log.info('teardown pre')208 self.log.info('teardown status: %s', self.status)209 self.log.info('teardown post')210class ExceptionTeardown(Test):211 def setUp(self):212 self.log.info('setup pre')213 self.log.info('setup post')214 def test(self):215 self.log.info('test pre')216 self.log.info('test post')217 def tearDown(self):218 self.log.info('teardown pre')219 self.log.info('teardown status: %s', self.status)220 raise ValueError221 # pylint: disable=W0101222 self.log.info('teardown post')223class KillTest(Test):224 def setUp(self):225 self.log.info('setup pre')226 self.log.info('setup post')227 def test(self):228 self.log.info('test pre')229 os.kill(os.getpid(), 9)230 self.log.info('test post')231 def tearDown(self):232 self.log.info('teardown pre')233 self.log.info('teardown status: %s', self.status)...
test_graph.py
Source:test_graph.py
1from nose import with_setup2from openalea.container import Graph34g=Graph()56def setup_func () :7 for i in xrange(10) :8 g.add_vertex(i)9 for i in xrange(9) :10 g.add_edge(i,i+1,i)1112def teardown_func () :13 g.clear()1415# ##########################################################16#17# Graph concept18#19# ##########################################################20@with_setup(setup_func,teardown_func)21def test_source () :22 for i in xrange(9) :23 assert g.source(i)==i2425@with_setup(setup_func,teardown_func)26def test_target () :27 for i in xrange(9) :28 assert g.target(i)==(i+1)2930@with_setup(setup_func,teardown_func)31def test_has_vertex () :32 for i in xrange(10) :33 assert g.has_vertex(i)3435@with_setup(setup_func,teardown_func)36def test_has_edge () :37 for i in xrange(9) :38 assert g.has_edge(i)3940@with_setup(setup_func,teardown_func)41def test_is_valid () :42 assert g.is_valid()4344# ##########################################################45#46# Vertex List Graph Concept47#48# ##########################################################49@with_setup(setup_func,teardown_func)50def test_vertices () :51 assert list(g.vertices())==range(10)5253@with_setup(setup_func,teardown_func)54def test_nb_vertices () :55 assert g.nb_vertices()==105657@with_setup(setup_func,teardown_func)58def test_in_neighbors () :59 for i in xrange(9) :60 assert list(g.in_neighbors(i+1))==[i]6162@with_setup(setup_func,teardown_func)63def test_out_neighbors () :64 for i in xrange(9) :65 assert list(g.out_neighbors(i))==[i+1]6667@with_setup(setup_func,teardown_func)68def test_neighbors () :69 for i in xrange(8) :70 neis=list(g.neighbors(i+1))71 assert i in neis72 assert i+2 in neis7374@with_setup(setup_func,teardown_func)75def test_nb_in_neighbors () :76 for i in xrange(9) :77 assert g.nb_in_neighbors(i+1)==17879@with_setup(setup_func,teardown_func)80def test_nb_out_neighbors () :81 for i in xrange(9) :82 assert g.nb_out_neighbors(i)==18384@with_setup(setup_func,teardown_func)85def test_nb_neighbors () :86 for i in xrange(8) :87 assert g.nb_neighbors(i+1)==28889@with_setup(setup_func,teardown_func)90def test_edge () :91 assert g.edge(0,1) == 092 assert g.edge(0,2) == None9394# ##########################################################95#96# Edge List Graph Concept97#98# ##########################################################99@with_setup(setup_func,teardown_func)100def test_edges () :101 assert list(g.edges())==range(9)102103@with_setup(setup_func,teardown_func)104def test_nb_edges () :105 assert g.nb_edges()==9106107@with_setup(setup_func,teardown_func)108def test_in_edges () :109 for i in xrange(9) :110 assert list(g.in_edges(i+1))==[i]111112@with_setup(setup_func,teardown_func)113def test_out_edges () :114 for i in xrange(9) :115 assert list(g.out_edges(i))==[i]116117@with_setup(setup_func,teardown_func)118def test_vertex_edges () :119 for i in xrange(8) :120 neis=list(g.edges(i+1))121 assert i in neis122 assert i+1 in neis123124@with_setup(setup_func,teardown_func)125def test_nb_in_edges () :126 for i in xrange(9) :127 assert g.nb_in_edges(i+1)==1128129@with_setup(setup_func,teardown_func)130def test_nb_out_edges () :131 for i in xrange(9) :132 assert g.nb_out_edges(i)==1133134@with_setup(setup_func,teardown_func)135def test_nb_edges () :136 for i in xrange(8) :137 assert g.nb_edges(i+1)==2138139# ##########################################################140#141# Mutable Vertex Graph concept142#143# ##########################################################144@with_setup(setup_func,teardown_func)145def test_add_vertex () :146 assert g.add_vertex(100)==100147 vid=g.add_vertex()148 assert g.has_vertex(vid)149150@with_setup(setup_func,teardown_func)151def test_remove_vertex () :152 g.remove_vertex(5)153 assert not g.has_vertex(5)154 assert not g.has_edge(4)155 assert not g.has_edge(5)156 assert 5 not in list(g.neighbors(6))157 assert 5 not in list(g.neighbors(4))158159@with_setup(setup_func,teardown_func)160def test_clear () :161 g.clear()162 assert g.nb_vertices()==0163 assert g.nb_edges()==0164165# ##########################################################166#167# Mutable Edge Graph concept168#169# ##########################################################170@with_setup(setup_func,teardown_func)171def test_add_edge () :172 assert g.add_edge(0,9,100)==100173 eid=g.add_edge(2,1)174 assert eid in list(g.in_edges(1))175 assert eid in list(g.out_edges(2))176177@with_setup(setup_func,teardown_func)178def test_remove_edge () :179 g.remove_edge(4)180 assert not g.has_edge(4)181 assert 4 not in list(g.neighbors(5))182 assert 5 not in list(g.neighbors(4))183184@with_setup(setup_func,teardown_func)185def test_clear_edges () :186 g.clear_edges()187 assert g.nb_vertices()==10188 assert g.nb_edges()==0189190# ##########################################################191#192# Extend Graph concept193#194# ##########################################################195@with_setup(setup_func,teardown_func)196def test_extend () :197 trans_vid,trans_eid=g.extend(g)198 assert len(trans_vid)==10
...
test_sync_fixture.py
Source:test_sync_fixture.py
1import pytest2@pytest.fixture3def sync_fix():4 return 'sync_fix'5@pytest.mark.trio6async def test_single_sync_fixture(sync_fix):7 assert sync_fix == 'sync_fix'8def test_single_yield_fixture(testdir):9 testdir.makepyfile(10 """11 import pytest12 events = []13 @pytest.fixture14 def fix1():15 events.append('fixture setup')16 yield 'fix1'17 events.append('fixture teardown')18 def test_before():19 assert not events20 @pytest.mark.trio21 async def test_actual_test(fix1):22 assert events == ['fixture setup']23 assert fix1 == 'fix1'24 def test_after():25 assert events == [26 'fixture setup',27 'fixture teardown',28 ]29 """30 )31 result = testdir.runpytest()32 result.assert_outcomes(passed=3)33def test_single_yield_fixture_with_async_deps(testdir):34 testdir.makepyfile(35 """36 import pytest37 import trio38 events = []39 @pytest.fixture40 async def fix0():41 events.append('fix0 setup')42 await trio.sleep(0)43 return 'fix0'44 @pytest.fixture45 def fix1(fix0):46 events.append('fix1 setup')47 yield 'fix1 - ' + fix048 events.append('fix1 teardown')49 def test_before():50 assert not events51 @pytest.mark.trio52 async def test_actual_test(fix1):53 assert events == ['fix0 setup', 'fix1 setup']54 assert fix1 == 'fix1 - fix0'55 def test_after():56 assert events == [57 'fix0 setup',58 'fix1 setup',59 'fix1 teardown',60 ]61 """62 )63 result = testdir.runpytest()64 result.assert_outcomes(passed=3)65def test_sync_yield_fixture_crashed_teardown_allow_other_teardowns(testdir):66 testdir.makepyfile(67 """68 import pytest69 import trio70 setup_events = set()71 teardown_events = set()72 @pytest.fixture73 async def force_async_fixture():74 pass75 @pytest.fixture76 def good_fixture(force_async_fixture):77 setup_events.add('good_fixture setup')78 yield79 teardown_events.add('good_fixture teardown')80 @pytest.fixture81 def bad_fixture(force_async_fixture):82 setup_events.add('bad_fixture setup')83 yield84 teardown_events.add('bad_fixture teardown')85 raise RuntimeError('Crash during fixture teardown')86 def test_before():87 assert not setup_events88 assert not teardown_events89 @pytest.mark.trio90 async def test_actual_test(bad_fixture, good_fixture):91 pass92 def test_after():93 assert setup_events == {94 'good_fixture setup',95 'bad_fixture setup',96 }97 assert teardown_events == {98 'bad_fixture teardown',99 'good_fixture teardown',100 }101 """102 )103 result = testdir.runpytest()104 result.assert_outcomes(failed=1, passed=2)105 result.stdout.re_match_lines(106 [r'E\W+RuntimeError: Crash during fixture teardown']...
test_conftest.py
Source:test_conftest.py
...6def test_foo_fail():7 LOG.tc_step("I'm a step hahaha")8 assert 09@fixture(scope='function')10def fail_teardown(request):11 LOG.info("In setup now")12 def teardown():13 LOG.info("In teardown now")14 assert 0, 'teardown fail here'15 request.addfinalizer(teardown)16 return17def test_foo_multifail(fail_teardown):18 LOG.tc_step("I'm a step hahaha")19 assert 0, 'test call fail here'20@mark.skipif(True, reason="i'm testing skip")21def test_foo_skip():22 LOG.tc_step("I'm a step hahaha")23@fixture(scope='module', params=['fix1_1', 'fix1_2'])24def fix1(request):25 LOG.info('fix1 setup. param: {}'.format(request.param))26 def td():27 LOG.info('fix1 teardown. param: {}'.format(request.param))28 request.addfinalizer(td)29 return30@fixture(scope='module', params=['fix2_1', 'fix2_2'])31def fix2(request, fix1):32 LOG.info('fix2 setup. param: {}'.format(request.param))33 def td():34 LOG.info('fix2 teardown. param: {}'.format(request.param))35 request.addfinalizer(td)36 return37def test_fixtures(fix2):38 LOG.info("in test")39used = 040@fixture(scope='module', autouse=True)41def fix_autouse(request):42 global used43 used += 144 LOG.fixture_step("I'm MODULE a autouse fixture step. Used: {}".format(used))45 def fix_teardown():46 LOG.fixture_step("I'm a MODULE autouse fixture teardown. Used: {}".format(used))47 request.addfinalizer(fix_teardown)48@fixture(scope='function')49def fix_usefixture(request):50 LOG.fixture_step("I'm a usefixture fixture step")51 def fix_teardown():52 LOG.fixture_step("I'm a usefixture teardown")53 request.addfinalizer(fix_teardown)54@fixture(scope='function')55def fix_testparam(request):56 LOG.fixture_step("I'm a testparam fixture step")57 def fix_teardown():58 LOG.fixture_step("I'm a testparam teardown")59 request.addfinalizer(fix_teardown)60 return "testparam returned"61test_iter = 062@mark.usefixtures('fix_usefixture')63@mark.parametrize('test', ['atest', 'btest', 'ctest'])64def test_stress(fix_testparam, test):65 LOG.tc_step("Hey i'm a test step")66 LOG.tc_step(str(fix_testparam))67 global test_iter68 if test_iter > 0:69 assert 0, "Test function failed"...
test_classic_fixtures.py
Source:test_classic_fixtures.py
1# file basic_fixtures.py2import pytest3def setup():4 print("\t\t\t3 basic setup into module")5def teardown():6 print("\t\t\t3 basic teardown into module")7def setup_module(module):8 print("\n\t1 module setup")9def teardown_module(module):10 print("\t1 module teardown")11def setup_function(function):12 print("\t\t2 function setup")13def teardown_function(function):14 print("\t\t2 function teardown")15def test_numbers_3_4():16 print("\t\t\ttest 3*4")17 assert 3 * 4 == 1218def test_strings_a_3():19 print("\t\t\ttest a*3")20 assert 'a' * 3 == 'aaa'21class TestUM:22 def setup(self):23 print("\t\t\t\t2.2 basic setup into class")24 def teardown(self):25 print("\t\t\t\t2.2 basic teardown into class")26 def setup_class(cls):27 print("\t\t2.0 class setup")28 def teardown_class(cls):29 print("\t\t2.0 class teardown")30 def setup_method(self, method):31 print("\t\t\t2.1 method setup")32 def teardown_method(self, method):33 print("\t\t\t2.1 method teardown")34 def test_numbers_5_6(self):35 print("\t\t\t\ttest 5*6")36 assert 5 * 6 == 3037 def test_strings_b_2(self):38 print("\t\t\t\ttest b*2")...
Using AI Code Generation
1const { teardown } = require('storybook-test-runner');2describe('test', () => {3 afterAll(async () => {4 await teardown();5 });6 it('test', () => {7 expect(true).toBe(true);8 });9});10const { teardown } = require('storybook-test-runner');11const puppeteer = require('puppeteer');12describe('test', () => {13 afterAll(async () => {14 await teardown();15 await puppeteer.close();16 });17 it('test', () => {18 expect(true).toBe(true);19 });20});21const { teardown } = require('storybook-test-runner');22const puppeteer = require('puppeteer');23describe('test', () => {24 afterAll(async () => {25 await teardown();26 await puppeteer.close();27 });28 it('test', () => {29 expect(true).toBe(true);30 });31});32const { teardown } = require('storybook-test-runner');33const puppeteer = require('puppeteer');34const { teardown: teardownJestPuppeteer } = require('jest-puppeteer');35describe('test', () => {36 afterAll(async () => {37 await teardown();38 await teardownJestPuppeteer();39 await puppeteer.close();40 });41 it('test', () => {42 expect(true).toBe(true);43 });44});45const { teardown } = require('storybook-test-runner');46const puppeteer = require('puppeteer');47const { teardown: teardownJestPuppeteer } = require('jest-puppeteer');48describe('test', () => {49 afterAll(async () => {50 await teardown();51 await teardownJestPuppeteer();52 await puppeteer.close();53 });54 it('test', () => {55 expect(true).toBe(true);56 });57});58const { teardown } = require('storybook-test-runner');59const puppeteer = require('puppeteer');60const { teardown: teardownJestPuppeteer } = require('jest-puppeteer');61describe('test', () => {
Using AI Code Generation
1import { teardown } from 'storybook-test-runner';2import { storybookTestRunner } from 'storybook-test-runner';3describe('test', () => {4 after(() => {5 teardown();6 });7});8import { teardown } from 'storybook-test-runner';9import { storybookTestRunner } from 'storybook-test-runner';10describe('test', () => {11 storybookTestRunner({12 viewport: { width: 800, height: 600 },13 });14 after(() => {15 teardown();16 });17});18import { teardown } from 'storybook-test-runner';19import { storybookTestRunner } from 'storybook-test-runner';20describe('test', () => {21 storybookTestRunner({22 viewport: { width: 800, height: 600 },23 options: {24 },25 });26 after(() => {27 teardown();28 });29});30import { teardown } from 'storybook-test-runner';31import { storybookTestRunner } from 'storybook-test-runner';32describe('test', () => {33 storybookTestRunner({34 viewport: { width:
Using AI Code Generation
1import { storiesOf } from '@storybook/react'2import { StorybookTestRunner } from 'storybook-test-runner'3const storybookTestRunner = new StorybookTestRunner()4storiesOf('Button', module)5 .add('with text', () => {6 storybookTestRunner.teardown()7 })8import { storiesOf } from '@storybook/react'9import { StorybookTestRunner } from 'storybook-test-runner'10const storybookTestRunner = new StorybookTestRunner()11storiesOf('Button', module)12 .add('with text', () => {13 storybookTestRunner.teardown()14 })15import { storiesOf } from '@storybook/react'16import { StorybookTestRunner } from 'storybook-test-runner'17const storybookTestRunner = new StorybookTestRunner()18storiesOf('Button', module)19 .add('with text', () => {20 storybookTestRunner.teardown()21 })22import { storiesOf } from '@storybook/react'23import { StorybookTestRunner } from 'storybook-test-runner'24const storybookTestRunner = new StorybookTestRunner()25storiesOf('Button', module)26 .add('with text', () => {27 storybookTestRunner.teardown()28 })29import { storiesOf } from '@storybook/react'30import { StorybookTestRunner } from 'storybook-test-runner'31const storybookTestRunner = new StorybookTestRunner()32storiesOf('Button', module)33 .add('with text', () => {34 storybookTestRunner.teardown()35 })36import { storiesOf } from '@storybook/react'37import { StorybookTestRunner } from 'storybook-test-runner'38const storybookTestRunner = new StorybookTestRunner()39storiesOf('Button', module)40 .add('with text', () => {
Using AI Code Generation
1import { teardown } from 'storybook-test-runner'2afterEach(async () => {3 await teardown()4})5import { teardown } from 'storybook-test-runner'6afterEach(async () => {7 await teardown()8})9import { teardown } from 'storybook-test-runner'10afterEach(async () => {11 await teardown()12})13import { teardown } from 'storybook-test-runner'14afterEach(async () => {15 await teardown()16})17import { teardown } from 'storybook-test-runner'18afterEach(async () => {19 await teardown()20})21import { teardown } from 'storybook-test-runner'22afterEach(async () => {23 await teardown()24})25import { teardown } from 'storybook-test-runner'26afterEach(async () => {27 await teardown()28})29import { teardown } from 'storybook-test-runner'30afterEach(async () => {31 await teardown()32})33import { teardown } from 'storybook-test-runner'34afterEach(async () => {35 await teardown()36})37import { teardown } from 'storybook-test-runner'38afterEach(async () => {39 await teardown()40})41import { teardown } from 'storybook-test-runner'42afterEach(async () => {43 await teardown()44})45import { teardown } from 'storybook-test-runner'46afterEach(async () => {47 await teardown()48})49import { teardown } from 'storybook-test-runner'
Using AI Code Generation
1import { teardown } from 'storybook-test-runner';2import { stories } from './story.js';3stories.forEach((story) => {4 teardown(story);5});6import { setup } from 'storybook-test-runner';7import { storiesOf } from '@storybook/html';8const stories = storiesOf('Test', module);9stories.add('test', () => {10 setup(story);11 `;12});
Using AI Code Generation
1import { runTests } from 'storybook-test-runner';2runTests({3 teardown: () => {4 }5});6import { runTests } from 'storybook-test-runner';7runTests({8 teardown: () => {9 }10});11import { runTests } from 'storybook-test-runner';12runTests({13 teardown: () => {14 }15});16import { runTests } from 'storybook-test-runner';17runTests({18 teardown: () => {19 }20});21import { runTests } from 'storybook-test-runner';22runTests({23 teardown: () => {24 }25});26import { runTests } from 'storybook-test-runner';27runTests({28 teardown: () => {29 }30});31import { runTests } from 'storybook-test-runner';32runTests({33 teardown: () => {34 }35});36import { runTests } from 'storybook-test-runner';37runTests({38 teardown: () => {39 }40});41import { run
Using AI Code Generation
1import { teardown } from 'storybook-test-runner';2afterAll(() => {3 teardown();4});5import { initStoryshots } from '@storybook/addon-storyshots';6initStoryshots();
Using AI Code Generation
1import testStory from 'storybook-test-runner';2}, {3 teardown: () => {4 }5});6import testStory from 'storybook-test-runner';7}, {8 teardown: () => {9 }10});11import React from 'react';12import { storiesOf } from '@storybook/react';13import Button from './Button';14storiesOf('Button', module)15 .add('with text', () => (16 ), {17 teardown: () => {18 }19 });20import React from 'react';21export default function Button({ children }) {22 return (23 {children}24 );25}26import React from 'react';27import ReactDOM from 'react-dom';28import Button from './Button';29it('renders without crashing', () => {30 const div = document.createElement('div');31 ReactDOM.render(<Button />, div);32 ReactDOM.unmountComponentAtNode(div);33});34import testStory from 'storybook-test-runner';35}, {36 teardown: () => {37 }38});39import testStory from 'storybook-test-runner';40}, {41 teardown: () => {42 }43});44import testStory from 'storybook-test-runner';45}, {46 teardown: () => {47 }48});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!