Best Python code snippet using ATX
test_NmapArgs.py
Source:test_NmapArgs.py
...5 @pytest.mark.nmapargs6 def test_set_always_dns_resolution(self):7 args = NmapArgs(always_dns_resolution='foo')8 assert 'foo' == args.get_always_dns_resolution()9 assert not args.is_locked()10 args.set_always_dns_resolution('value')11 assert 'value' == args.get_always_dns_resolution()12 args.lock()13 assert args.is_locked()14 args.set_always_dns_resolution('new_value')15 assert 'value' == args.get_always_dns_resolution()16 cloned_args = args.clone()17 assert not cloned_args.is_locked()18 assert 'value' == cloned_args.get_always_dns_resolution()19 @pytest.mark.nmap20 @pytest.mark.nmapargs21 def test_set_never_dns_resolution(self):22 args = NmapArgs(never_dns_resolution='foo')23 assert 'foo' == args.get_never_dns_resolution()24 assert not args.is_locked()25 args.set_never_dns_resolution('value')26 assert 'value' == args.get_never_dns_resolution()27 args.lock()28 assert args.is_locked()29 args.set_never_dns_resolution('new_value')30 assert 'value' == args.get_never_dns_resolution()31 cloned_args = args.clone()32 assert not cloned_args.is_locked()33 assert 'value' == cloned_args.get_never_dns_resolution()34 @pytest.mark.nmap35 @pytest.mark.nmapargs36 def test_set_port_ratio(self):37 args = NmapArgs(port_ratio='foo')38 assert 'foo' == args.get_port_ratio()39 assert not args.is_locked()40 args.set_port_ratio('value')41 assert 'value' == args.get_port_ratio()42 args.lock()43 assert args.is_locked()44 args.set_port_ratio('new_value')45 assert 'value' == args.get_port_ratio()46 cloned_args = args.clone()47 assert not cloned_args.is_locked()48 assert 'value' == cloned_args.get_port_ratio()49 @pytest.mark.nmap50 @pytest.mark.nmapargs51 def test_set_top_ports(self):52 args = NmapArgs(top_ports='foo')53 assert 'foo' == args.get_top_ports()54 assert not args.is_locked()55 args.set_top_ports('value')56 assert 'value' == args.get_top_ports()57 args.lock()58 assert args.is_locked()59 args.set_top_ports('new_value')60 assert 'value' == args.get_top_ports()61 cloned_args = args.clone()62 assert not cloned_args.is_locked()63 assert 'value' == cloned_args.get_top_ports()64 @pytest.mark.nmap65 @pytest.mark.nmapargs66 def test_set_scan_consecutively(self):67 args = NmapArgs(scan_consecutively='foo')68 assert 'foo' == args.get_scan_consecutively()69 assert not args.is_locked()70 args.set_scan_consecutively('value')71 assert 'value' == args.get_scan_consecutively()72 args.lock()73 assert args.is_locked()74 args.set_scan_consecutively('new_value')75 assert 'value' == args.get_scan_consecutively()76 cloned_args = args.clone()77 assert not cloned_args.is_locked()78 assert 'value' == cloned_args.get_scan_consecutively()79 @pytest.mark.nmap80 @pytest.mark.nmapargs81 def test_set_fast_mode(self):82 args = NmapArgs(fast_mode='foo')83 assert 'foo' == args.get_fast_mode()84 assert not args.is_locked()85 args.set_fast_mode('value')86 assert 'value' == args.get_fast_mode()87 args.lock()88 assert args.is_locked()89 args.set_fast_mode('new_value')90 assert 'value' == args.get_fast_mode()91 cloned_args = args.clone()92 assert not cloned_args.is_locked()93 assert 'value' == cloned_args.get_fast_mode()94 @pytest.mark.nmap95 @pytest.mark.nmapargs96 def test_set_exclude_ports(self):97 args = NmapArgs(exclude_ports='foo')98 assert 'foo' == args.get_exclude_ports()99 assert not args.is_locked()100 args.set_exclude_ports('value')101 assert 'value' == args.get_exclude_ports()102 args.lock()103 assert args.is_locked()104 args.set_exclude_ports('new_value')105 assert 'value' == args.get_exclude_ports()106 cloned_args = args.clone()107 assert not cloned_args.is_locked()108 assert 'value' == cloned_args.get_exclude_ports()109 @pytest.mark.nmap110 @pytest.mark.nmapargs111 def test_set_version_all(self):112 args = NmapArgs(version_all='foo')113 assert 'foo' == args.get_version_all()114 assert not args.is_locked()115 args.set_version_all('value')116 assert 'value' == args.get_version_all()117 args.lock()118 assert args.is_locked()119 args.set_version_all('new_value')120 assert 'value' == args.get_version_all()121 cloned_args = args.clone()122 assert not cloned_args.is_locked()123 assert 'value' == cloned_args.get_version_all()124 @pytest.mark.nmap125 @pytest.mark.nmapargs126 def test_set_script_trace(self):127 args = NmapArgs(script_trace='foo')128 assert 'foo' == args.get_script_trace()129 assert not args.is_locked()130 args.set_script_trace('value')131 assert 'value' == args.get_script_trace()132 args.lock()133 assert args.is_locked()134 args.set_script_trace('new_value')135 assert 'value' == args.get_script_trace()136 cloned_args = args.clone()137 assert not cloned_args.is_locked()138 assert 'value' == cloned_args.get_script_trace()139 @pytest.mark.nmap140 @pytest.mark.nmapargs141 def test_set_version_light(self):142 args = NmapArgs(version_light='foo')143 assert 'foo' == args.get_version_light()144 assert not args.is_locked()145 args.set_version_light('value')146 assert 'value' == args.get_version_light()147 args.lock()148 assert args.is_locked()149 args.set_version_light('new_value')150 assert 'value' == args.get_version_light()151 cloned_args = args.clone()152 assert not cloned_args.is_locked()153 assert 'value' == cloned_args.get_version_light()154 @pytest.mark.nmap155 @pytest.mark.nmapargs156 def test_set_version_intensity(self):157 args = NmapArgs(version_intensity='foo')158 assert 'foo' == args.get_version_intensity()159 assert not args.is_locked()160 args.set_version_intensity('value')161 assert 'value' == args.get_version_intensity()162 args.lock()163 assert args.is_locked()164 args.set_version_intensity('new_value')165 assert 'value' == args.get_version_intensity()166 cloned_args = args.clone()167 assert not cloned_args.is_locked()168 assert 'value' == cloned_args.get_version_intensity()169 @pytest.mark.nmap170 @pytest.mark.nmapargs171 def test_set_service_discovery(self):172 args = NmapArgs(service_discovery='foo')173 assert 'foo' == args.get_service_discovery()174 assert not args.is_locked()175 args.set_service_discovery('value')176 assert 'value' == args.get_service_discovery()177 args.lock()178 assert args.is_locked()179 args.set_service_discovery('new_value')180 assert 'value' == args.get_service_discovery()181 cloned_args = args.clone()182 assert not cloned_args.is_locked()183 assert 'value' == cloned_args.get_service_discovery()184 @pytest.mark.nmap185 @pytest.mark.nmapargs186 def test_set_pn(self):187 args = NmapArgs(pn='foo')188 assert 'foo' == args.get_pn()189 assert not args.is_locked()190 args.set_pn('value')191 assert 'value' == args.get_pn()192 args.lock()193 assert args.is_locked()194 args.set_pn('new_value')195 assert 'value' == args.get_pn()196 cloned_args = args.clone()197 assert not cloned_args.is_locked()198 assert 'value' == cloned_args.get_pn()199 @pytest.mark.nmap200 @pytest.mark.nmapargs201 def test_set_script_args(self):202 args = NmapArgs(script_args='foo')203 assert 'foo' == args.get_script_args()204 assert not args.is_locked()205 args.set_script_args('value')206 assert 'value' == args.get_script_args()207 args.lock()208 assert args.is_locked()209 args.set_script_args('new_value')210 assert 'value' == args.get_script_args()211 cloned_args = args.clone()212 assert not cloned_args.is_locked()213 assert 'value' == cloned_args.get_script_args()214 @pytest.mark.nmap215 @pytest.mark.nmapargs216 def test_set_scripts(self):217 args = NmapArgs(scripts='foo')218 assert 'foo' == args.get_scripts()219 assert not args.is_locked()220 args.set_scripts('value')221 assert 'value' == args.get_scripts()222 args.lock()223 assert args.is_locked()224 args.set_scripts('new_value')225 assert 'value' == args.get_scripts()226 cloned_args = args.clone()227 assert not cloned_args.is_locked()228 assert 'value' == cloned_args.get_scripts()229 @pytest.mark.nmap230 @pytest.mark.nmapargs231 def test_set_default_script(self):232 args = NmapArgs(default_script='foo')233 assert 'foo' == args.get_default_script()234 assert not args.is_locked()235 args.set_default_script('value')236 assert 'value' == args.get_default_script()237 args.lock()238 assert args.is_locked()239 args.set_default_script('new_value')240 assert 'value' == args.get_default_script()241 cloned_args = args.clone()242 assert not cloned_args.is_locked()243 assert 'value' == cloned_args.get_default_script()244 @pytest.mark.nmap245 @pytest.mark.nmapargs246 def test_set_version_trace(self):247 args = NmapArgs(version_trace='foo')248 assert 'foo' == args.get_version_trace()249 assert not args.is_locked()250 args.set_version_trace('value')251 assert 'value' == args.get_version_trace()252 args.lock()253 assert args.is_locked()254 args.set_version_trace('new_value')255 assert 'value' == args.get_version_trace()256 cloned_args = args.clone()257 assert not cloned_args.is_locked()258 assert 'value' == cloned_args.get_version_trace()259 @pytest.mark.nmap260 @pytest.mark.nmapargs261 def test_set_min_hostgroup(self):262 args = NmapArgs(min_hostgroup='foo')263 assert 'foo' == args.get_min_hostgroup()264 assert not args.is_locked()265 args.set_min_hostgroup('value')266 assert 'value' == args.get_min_hostgroup()267 args.lock()268 assert args.is_locked()269 args.set_min_hostgroup('new_value')270 assert 'value' == args.get_min_hostgroup()271 cloned_args = args.clone()272 assert not cloned_args.is_locked()273 assert 'value' == cloned_args.get_min_hostgroup()274 @pytest.mark.nmap275 @pytest.mark.nmapargs276 def test_set_timing(self):277 args = NmapArgs(timing='foo')278 assert 'foo' == args.get_timing()279 assert not args.is_locked()280 args.set_timing('value')281 assert 'value' == args.get_timing()282 args.lock()283 assert args.is_locked()284 args.set_timing('new_value')285 assert 'value' == args.get_timing()286 cloned_args = args.clone()287 assert not cloned_args.is_locked()288 assert 'value' == cloned_args.get_timing()289 @pytest.mark.nmap290 @pytest.mark.nmapargs291 def test_set_os_scan_limit(self):292 args = NmapArgs(os_scan_limit='foo')293 assert 'foo' == args.get_os_scan_limit()294 assert not args.is_locked()295 args.set_os_scan_limit('value')296 assert 'value' == args.get_os_scan_limit()297 args.lock()298 assert args.is_locked()299 args.set_os_scan_limit('new_value')300 assert 'value' == args.get_os_scan_limit()301 cloned_args = args.clone()302 assert not cloned_args.is_locked()303 assert 'value' == cloned_args.get_os_scan_limit()304 @pytest.mark.nmap305 @pytest.mark.nmapargs306 def test_set_os_guess(self):307 args = NmapArgs(os_guess='foo')308 assert 'foo' == args.get_os_guess()309 assert not args.is_locked()310 args.set_os_guess('value')311 assert 'value' == args.get_os_guess()312 args.lock()313 assert args.is_locked()314 args.set_os_guess('new_value')315 assert 'value' == args.get_os_guess()316 cloned_args = args.clone()317 assert not cloned_args.is_locked()318 assert 'value' == cloned_args.get_os_guess()319 @pytest.mark.nmap320 @pytest.mark.nmapargs321 def test_set_os_detection(self):322 args = NmapArgs(os_detection='foo')323 assert 'foo' == args.get_os_detection()324 assert not args.is_locked()325 args.set_os_detection('value')326 assert 'value' == args.get_os_detection()327 args.lock()328 assert args.is_locked()329 args.set_os_detection('new_value')330 assert 'value' == args.get_os_detection()331 cloned_args = args.clone()332 assert not cloned_args.is_locked()333 assert 'value' == cloned_args.get_os_detection()334 @pytest.mark.nmap335 @pytest.mark.nmapargs336 def test_set_min_rtt_timeout(self):337 args = NmapArgs(min_rtt_timeout='foo')338 assert 'foo' == args.get_min_rtt_timeout()339 assert not args.is_locked()340 args.set_min_rtt_timeout('value')341 assert 'value' == args.get_min_rtt_timeout()342 args.lock()343 assert args.is_locked()344 args.set_min_rtt_timeout('new_value')345 assert 'value' == args.get_min_rtt_timeout()346 cloned_args = args.clone()347 assert not cloned_args.is_locked()348 assert 'value' == cloned_args.get_min_rtt_timeout()349 @pytest.mark.nmap350 @pytest.mark.nmapargs351 def test_set_max_parallelism(self):352 args = NmapArgs(max_parallelism='foo')353 assert 'foo' == args.get_max_parallelism()354 assert not args.is_locked()355 args.set_max_parallelism('value')356 assert 'value' == args.get_max_parallelism()357 args.lock()358 assert args.is_locked()359 args.set_max_parallelism('new_value')360 assert 'value' == args.get_max_parallelism()361 cloned_args = args.clone()362 assert not cloned_args.is_locked()363 assert 'value' == cloned_args.get_max_parallelism()364 @pytest.mark.nmap365 @pytest.mark.nmapargs366 def test_set_min_parallelism(self):367 args = NmapArgs(min_parallelism='foo')368 assert 'foo' == args.get_min_parallelism()369 assert not args.is_locked()370 args.set_min_parallelism('value')371 assert 'value' == args.get_min_parallelism()372 args.lock()373 assert args.is_locked()374 args.set_min_parallelism('new_value')375 assert 'value' == args.get_min_parallelism()376 cloned_args = args.clone()377 assert not cloned_args.is_locked()378 assert 'value' == cloned_args.get_min_parallelism()379 @pytest.mark.nmap380 @pytest.mark.nmapargs381 def test_set_max_hostgroup(self):382 args = NmapArgs(max_hostgroup='foo')383 assert 'foo' == args.get_max_hostgroup()384 assert not args.is_locked()385 args.set_max_hostgroup('value')386 assert 'value' == args.get_max_hostgroup()387 args.lock()388 assert args.is_locked()389 args.set_max_hostgroup('new_value')390 assert 'value' == args.get_max_hostgroup()391 cloned_args = args.clone()392 assert not cloned_args.is_locked()393 assert 'value' == cloned_args.get_max_hostgroup()394 @pytest.mark.nmap395 @pytest.mark.nmapargs396 def test_set_scan_delay(self):397 args = NmapArgs(scan_delay='foo')398 assert 'foo' == args.get_scan_delay()399 assert not args.is_locked()400 args.set_scan_delay('value')401 assert 'value' == args.get_scan_delay()402 args.lock()403 assert args.is_locked()404 args.set_scan_delay('new_value')405 assert 'value' == args.get_scan_delay()406 cloned_args = args.clone()407 assert not cloned_args.is_locked()408 assert 'value' == cloned_args.get_scan_delay()409 @pytest.mark.nmap410 @pytest.mark.nmapargs411 def test_set_host_timeout(self):412 args = NmapArgs(host_timeout='foo')413 assert 'foo' == args.get_host_timeout()414 assert not args.is_locked()415 args.set_host_timeout('value')416 assert 'value' == args.get_host_timeout()417 args.lock()418 assert args.is_locked()419 args.set_host_timeout('new_value')420 assert 'value' == args.get_host_timeout()421 cloned_args = args.clone()422 assert not cloned_args.is_locked()423 assert 'value' == cloned_args.get_host_timeout()424 @pytest.mark.nmap425 @pytest.mark.nmapargs426 def test_set_max_retries(self):427 args = NmapArgs(max_retries='foo')428 assert 'foo' == args.get_max_retries()429 assert not args.is_locked()430 args.set_max_retries('value')431 assert 'value' == args.get_max_retries()432 args.lock()433 assert args.is_locked()434 args.set_max_retries('new_value')435 assert 'value' == args.get_max_retries()436 cloned_args = args.clone()437 assert not cloned_args.is_locked()438 assert 'value' == cloned_args.get_max_retries()439 @pytest.mark.nmap440 @pytest.mark.nmapargs441 def test_set_initial_rtt_timeout(self):442 args = NmapArgs(initial_rtt_timeout='foo')443 assert 'foo' == args.get_initial_rtt_timeout()444 assert not args.is_locked()445 args.set_initial_rtt_timeout('value')446 assert 'value' == args.get_initial_rtt_timeout()447 args.lock()448 assert args.is_locked()449 args.set_initial_rtt_timeout('new_value')450 assert 'value' == args.get_initial_rtt_timeout()451 cloned_args = args.clone()452 assert not cloned_args.is_locked()453 assert 'value' == cloned_args.get_initial_rtt_timeout()454 @pytest.mark.nmap455 @pytest.mark.nmapargs456 def test_set_privileged(self):457 args = NmapArgs(privileged='foo')458 assert 'foo' == args.get_privileged()459 assert not args.is_locked()460 args.set_privileged('value')461 assert 'value' == args.get_privileged()462 args.lock()463 assert args.is_locked()464 args.set_privileged('new_value')465 assert 'value' == args.get_privileged()466 cloned_args = args.clone()467 assert not cloned_args.is_locked()468 assert 'value' == cloned_args.get_privileged()469 @pytest.mark.nmap470 @pytest.mark.nmapargs471 def test_set_max_rtt_timeout(self):472 args = NmapArgs(max_rtt_timeout='foo')473 assert 'foo' == args.get_max_rtt_timeout()474 assert not args.is_locked()475 args.set_max_rtt_timeout('value')476 assert 'value' == args.get_max_rtt_timeout()477 args.lock()478 assert args.is_locked()479 args.set_max_rtt_timeout('new_value')480 assert 'value' == args.get_max_rtt_timeout()481 cloned_args = args.clone()482 assert not cloned_args.is_locked()483 assert 'value' == cloned_args.get_max_rtt_timeout()484 @pytest.mark.nmap485 @pytest.mark.nmapargs486 def test_set_decoys(self):487 args = NmapArgs(decoys='foo')488 assert 'foo' == args.get_decoys()489 assert not args.is_locked()490 args.set_decoys('value')491 assert 'value' == args.get_decoys()492 args.lock()493 assert args.is_locked()494 args.set_decoys('new_value')495 assert 'value' == args.get_decoys()496 cloned_args = args.clone()497 assert not cloned_args.is_locked()498 assert 'value' == cloned_args.get_decoys()499 @pytest.mark.nmap500 @pytest.mark.nmapargs501 def test_set_mtu(self):502 args = NmapArgs(mtu='foo')503 assert 'foo' == args.get_mtu()504 assert not args.is_locked()505 args.set_mtu('value')506 assert 'value' == args.get_mtu()507 args.lock()508 assert args.is_locked()509 args.set_mtu('new_value')510 assert 'value' == args.get_mtu()511 cloned_args = args.clone()512 assert not cloned_args.is_locked()513 assert 'value' == cloned_args.get_mtu()514 @pytest.mark.nmap515 @pytest.mark.nmapargs516 def test_set_misc_a(self):517 args = NmapArgs(misc_a='foo')518 assert 'foo' == args.get_misc_a()519 assert not args.is_locked()520 args.set_misc_a('value')521 assert 'value' == args.get_misc_a()522 args.lock()523 assert args.is_locked()524 args.set_misc_a('new_value')525 assert 'value' == args.get_misc_a()526 cloned_args = args.clone()527 assert not cloned_args.is_locked()528 assert 'value' == cloned_args.get_misc_a()529 @pytest.mark.nmap530 @pytest.mark.nmapargs531 def test_set_datadir(self):532 args = NmapArgs(datadir='foo')533 assert 'foo' == args.get_datadir()534 assert not args.is_locked()535 args.set_datadir('value')536 assert 'value' == args.get_datadir()537 args.lock()538 assert args.is_locked()539 args.set_datadir('new_value')540 assert 'value' == args.get_datadir()541 cloned_args = args.clone()542 assert not cloned_args.is_locked()543 assert 'value' == cloned_args.get_datadir()544 @pytest.mark.nmap545 @pytest.mark.nmapargs546 def test_set_ipv6_scan(self):547 args = NmapArgs(ipv6_scan='foo')548 assert 'foo' == args.get_ipv6_scan()549 assert not args.is_locked()550 args.set_ipv6_scan('value')551 assert 'value' == args.get_ipv6_scan()552 args.lock()553 assert args.is_locked()554 args.set_ipv6_scan('new_value')555 assert 'value' == args.get_ipv6_scan()556 cloned_args = args.clone()557 assert not cloned_args.is_locked()558 assert 'value' == cloned_args.get_ipv6_scan()559 @pytest.mark.nmap560 @pytest.mark.nmapargs561 def test_set_max_rate(self):562 args = NmapArgs(max_rate='foo')563 assert 'foo' == args.get_max_rate()564 assert not args.is_locked()565 args.set_max_rate('value')566 assert 'value' == args.get_max_rate()567 args.lock()568 assert args.is_locked()569 args.set_max_rate('new_value')570 assert 'value' == args.get_max_rate()571 cloned_args = args.clone()572 assert not cloned_args.is_locked()573 assert 'value' == cloned_args.get_max_rate()574 @pytest.mark.nmap575 @pytest.mark.nmapargs576 def test_set_min_rate(self):577 args = NmapArgs(min_rate='foo')578 assert 'foo' == args.get_min_rate()579 assert not args.is_locked()580 args.set_min_rate('value')581 assert 'value' == args.get_min_rate()582 args.lock()583 assert args.is_locked()584 args.set_min_rate('new_value')585 assert 'value' == args.get_min_rate()586 cloned_args = args.clone()587 assert not cloned_args.is_locked()588 assert 'value' == cloned_args.get_min_rate()589 @pytest.mark.nmap590 @pytest.mark.nmapargs591 def test_set_data_string(self):592 args = NmapArgs(data_string='foo')593 assert 'foo' == args.get_data_string()594 assert not args.is_locked()595 args.set_data_string('value')596 assert 'value' == args.get_data_string()597 args.lock()598 assert args.is_locked()599 args.set_data_string('new_value')600 assert 'value' == args.get_data_string()601 cloned_args = args.clone()602 assert not cloned_args.is_locked()603 assert 'value' == cloned_args.get_data_string()604 @pytest.mark.nmap605 @pytest.mark.nmapargs606 def test_set_data(self):607 args = NmapArgs(data='foo')608 assert 'foo' == args.get_data()609 assert not args.is_locked()610 args.set_data('value')611 assert 'value' == args.get_data()612 args.lock()613 assert args.is_locked()614 args.set_data('new_value')615 assert 'value' == args.get_data()616 cloned_args = args.clone()617 assert not cloned_args.is_locked()618 assert 'value' == cloned_args.get_data()619 @pytest.mark.nmap620 @pytest.mark.nmapargs621 def test_set_proxies(self):622 args = NmapArgs(proxies='foo')623 assert 'foo' == args.get_proxies()624 assert not args.is_locked()625 args.set_proxies('value')626 assert 'value' == args.get_proxies()627 args.lock()628 assert args.is_locked()629 args.set_proxies('new_value')630 assert 'value' == args.get_proxies()631 cloned_args = args.clone()632 assert not cloned_args.is_locked()633 assert 'value' == cloned_args.get_proxies()634 @pytest.mark.nmap635 @pytest.mark.nmapargs636 def test_set_source_port(self):637 args = NmapArgs(source_port='foo')638 assert 'foo' == args.get_source_port()639 assert not args.is_locked()640 args.set_source_port('value')641 assert 'value' == args.get_source_port()642 args.lock()643 assert args.is_locked()644 args.set_source_port('new_value')645 assert 'value' == args.get_source_port()646 cloned_args = args.clone()647 assert not cloned_args.is_locked()648 assert 'value' == cloned_args.get_source_port()649 @pytest.mark.nmap650 @pytest.mark.nmapargs651 def test_set_send_ip(self):652 args = NmapArgs(send_ip='foo')653 assert 'foo' == args.get_send_ip()654 assert not args.is_locked()655 args.set_send_ip('value')656 assert 'value' == args.get_send_ip()657 args.lock()658 assert args.is_locked()659 args.set_send_ip('new_value')660 assert 'value' == args.get_send_ip()661 cloned_args = args.clone()662 assert not cloned_args.is_locked()663 assert 'value' == cloned_args.get_send_ip()664 @pytest.mark.nmap665 @pytest.mark.nmapargs666 def test_set_unprivileged(self):667 args = NmapArgs(unprivileged='foo')668 assert 'foo' == args.get_unprivileged()669 assert not args.is_locked()670 args.set_unprivileged('value')671 assert 'value' == args.get_unprivileged()672 args.lock()673 assert args.is_locked()674 args.set_unprivileged('new_value')675 assert 'value' == args.get_unprivileged()676 cloned_args = args.clone()677 assert not cloned_args.is_locked()678 assert 'value' == cloned_args.get_unprivileged()679 @pytest.mark.nmap680 @pytest.mark.nmapargs681 def test_set_send_eth(self):682 args = NmapArgs(send_eth='foo')683 assert 'foo' == args.get_send_eth()684 assert not args.is_locked()685 args.set_send_eth('value')686 assert 'value' == args.get_send_eth()687 args.lock()688 assert args.is_locked()689 args.set_send_eth('new_value')690 assert 'value' == args.get_send_eth()691 cloned_args = args.clone()692 assert not cloned_args.is_locked()693 assert 'value' == cloned_args.get_send_eth()694 @pytest.mark.nmap695 @pytest.mark.nmapargs696 def test_set_max_scan_delay(self):697 args = NmapArgs(max_scan_delay='foo')698 assert 'foo' == args.get_max_scan_delay()699 assert not args.is_locked()700 args.set_max_scan_delay('value')701 assert 'value' == args.get_max_scan_delay()702 args.lock()703 assert args.is_locked()704 args.set_max_scan_delay('new_value')705 assert 'value' == args.get_max_scan_delay()706 cloned_args = args.clone()707 assert not cloned_args.is_locked()708 assert 'value' == cloned_args.get_max_scan_delay()709 @pytest.mark.nmap710 @pytest.mark.nmapargs711 def test_set_interface(self):712 args = NmapArgs(interface='foo')713 assert 'foo' == args.get_interface()714 assert not args.is_locked()715 args.set_interface('value')716 assert 'value' == args.get_interface()717 args.lock()718 assert args.is_locked()719 args.set_interface('new_value')720 assert 'value' == args.get_interface()721 cloned_args = args.clone()722 assert not cloned_args.is_locked()723 assert 'value' == cloned_args.get_interface()724 @pytest.mark.nmap725 @pytest.mark.nmapargs726 def test_set_spoof_ip(self):727 args = NmapArgs(spoof_ip='foo')728 assert 'foo' == args.get_spoof_ip()729 assert not args.is_locked()730 args.set_spoof_ip('value')731 assert 'value' == args.get_spoof_ip()732 args.lock()733 assert args.is_locked()734 args.set_spoof_ip('new_value')735 assert 'value' == args.get_spoof_ip()736 cloned_args = args.clone()737 assert not cloned_args.is_locked()738 assert 'value' == cloned_args.get_spoof_ip()739 @pytest.mark.nmap740 @pytest.mark.nmapargs741 def test_set_bad_sum(self):742 args = NmapArgs(bad_sum='foo')743 assert 'foo' == args.get_bad_sum()744 assert not args.is_locked()745 args.set_bad_sum('value')746 assert 'value' == args.get_bad_sum()747 args.lock()748 assert args.is_locked()749 args.set_bad_sum('new_value')750 assert 'value' == args.get_bad_sum()751 cloned_args = args.clone()752 assert not cloned_args.is_locked()753 assert 'value' == cloned_args.get_bad_sum()754 @pytest.mark.nmap755 @pytest.mark.nmapargs756 def test_set_spoof_mac(self):757 args = NmapArgs(spoof_mac='foo')758 assert 'foo' == args.get_spoof_mac()759 assert not args.is_locked()760 args.set_spoof_mac('value')761 assert 'value' == args.get_spoof_mac()762 args.lock()763 assert args.is_locked()764 args.set_spoof_mac('new_value')765 assert 'value' == args.get_spoof_mac()766 cloned_args = args.clone()767 assert not cloned_args.is_locked()768 assert 'value' == cloned_args.get_spoof_mac()769 @pytest.mark.nmap770 @pytest.mark.nmapargs771 def test_set_ttl(self):772 args = NmapArgs(ttl='foo')773 assert 'foo' == args.get_ttl()774 assert not args.is_locked()775 args.set_ttl('value')776 assert 'value' == args.get_ttl()777 args.lock()778 assert args.is_locked()779 args.set_ttl('new_value')780 assert 'value' == args.get_ttl()781 cloned_args = args.clone()782 assert not cloned_args.is_locked()783 assert 'value' == cloned_args.get_ttl()784 @pytest.mark.nmap785 @pytest.mark.nmapargs786 def test_set_ip_options(self):787 args = NmapArgs(ip_options='foo')788 assert 'foo' == args.get_ip_options()789 assert not args.is_locked()790 args.set_ip_options('value')791 assert 'value' == args.get_ip_options()792 args.lock()793 assert args.is_locked()794 args.set_ip_options('new_value')795 assert 'value' == args.get_ip_options()796 cloned_args = args.clone()797 assert not cloned_args.is_locked()798 assert 'value' == cloned_args.get_ip_options()799 @pytest.mark.nmap800 @pytest.mark.nmapargs801 def test_set_data_length(self):802 args = NmapArgs(data_length='foo')803 assert 'foo' == args.get_data_length()804 assert not args.is_locked()805 args.set_data_length('value')806 assert 'value' == args.get_data_length()807 args.lock()808 assert args.is_locked()809 args.set_data_length('new_value')810 assert 'value' == args.get_data_length()811 cloned_args = args.clone()812 assert not cloned_args.is_locked()813 assert 'value' == cloned_args.get_data_length()814 @pytest.mark.nmap815 @pytest.mark.nmapargs816 def test_set_ports(self):817 args = NmapArgs(ports='foo')818 assert 'foo' == args.get_ports()819 assert not args.is_locked()820 args.set_ports('value')821 assert 'value' == args.get_ports()822 args.lock()823 assert args.is_locked()824 args.set_ports('new_value')825 assert 'value' == args.get_ports()826 cloned_args = args.clone()827 assert not cloned_args.is_locked()828 assert 'value' == cloned_args.get_ports()829 @pytest.mark.nmap830 @pytest.mark.nmapargs831 def test_set_traceroute(self):832 args = NmapArgs(traceroute='foo')833 assert 'foo' == args.get_traceroute()834 assert not args.is_locked()835 args.set_traceroute('value')836 assert 'value' == args.get_traceroute()837 args.lock()838 assert args.is_locked()839 args.set_traceroute('new_value')840 assert 'value' == args.get_traceroute()841 cloned_args = args.clone()842 assert not cloned_args.is_locked()843 assert 'value' == cloned_args.get_traceroute()844 @pytest.mark.nmap845 @pytest.mark.nmapargs846 def test_set_system_dns(self):847 args = NmapArgs(system_dns='foo')848 assert 'foo' == args.get_system_dns()849 assert not args.is_locked()850 args.set_system_dns('value')851 assert 'value' == args.get_system_dns()852 args.lock()853 assert args.is_locked()854 args.set_system_dns('new_value')855 assert 'value' == args.get_system_dns()856 cloned_args = args.clone()857 assert not cloned_args.is_locked()858 assert 'value' == cloned_args.get_system_dns()859 @pytest.mark.nmap860 @pytest.mark.nmapargs861 def test_set_dns_servers(self):862 args = NmapArgs(dns_servers='foo')863 assert 'foo' == args.get_dns_servers()864 assert not args.is_locked()865 args.set_dns_servers('value')866 assert 'value' == args.get_dns_servers()867 args.lock()868 assert args.is_locked()869 args.set_dns_servers('new_value')870 assert 'value' == args.get_dns_servers()871 cloned_args = args.clone()872 assert not cloned_args.is_locked()873 assert 'value' == cloned_args.get_dns_servers()874 @pytest.mark.nmap875 @pytest.mark.nmapargs876 def test_set_exclude_hosts(self):877 args = NmapArgs(exclude_hosts='foo')878 assert 'foo' == args.get_exclude_hosts()879 assert not args.is_locked()880 args.set_exclude_hosts('value')881 assert 'value' == args.get_exclude_hosts()882 args.lock()883 assert args.is_locked()884 args.set_exclude_hosts('new_value')885 assert 'value' == args.get_exclude_hosts()886 cloned_args = args.clone()887 assert not cloned_args.is_locked()888 assert 'value' == cloned_args.get_exclude_hosts()889 @pytest.mark.nmap890 @pytest.mark.nmapargs891 def test_set_num_hosts(self):892 args = NmapArgs(num_hosts='foo')893 assert 'foo' == args.get_num_hosts()894 assert not args.is_locked()895 args.set_num_hosts('value')896 assert 'value' == args.get_num_hosts()897 args.lock()898 assert args.is_locked()899 args.set_num_hosts('new_value')900 assert 'value' == args.get_num_hosts()901 cloned_args = args.clone()902 assert not cloned_args.is_locked()903 assert 'value' == cloned_args.get_num_hosts()904 @pytest.mark.nmap905 @pytest.mark.nmapargs906 def test_set_hosts(self):907 args = NmapArgs(hosts='foo')908 assert 'foo' == args.get_hosts()909 assert not args.is_locked()910 args.set_hosts('value')911 assert 'value' == args.get_hosts()912 args.lock()913 assert args.is_locked()914 args.set_hosts('new_value')915 assert 'value' == args.get_hosts()916 cloned_args = args.clone()917 assert not cloned_args.is_locked()...
test_filelock.py
Source:test_filelock.py
1"""2Tests adapted and expanded from:3https://github.com/benediktschmitt/py-filelock/blob4/b30bdc4fb998f5f4350257235eb51147f9e81862/test.py5"""6import gc7from pathlib import Path8from itertools import repeat, chain9from concurrent.futures import ThreadPoolExecutor10import pytest11from aiuti.filelock import FileLock12from aiuti.typing import Yields13@pytest.fixture14def lock_file(tmp_path: Path) -> Yields[str]:15 """Temporary filepath for testing the lock."""16 lock_file = tmp_path / 'file.lock'17 if lock_file.exists():18 lock_file.unlink()19 yield str(lock_file)20 if lock_file.exists():21 lock_file.unlink()22@pytest.fixture23def flock(lock_file: str) -> FileLock:24 """Default file lock for testing."""25 return FileLock(lock_file)26@pytest.fixture27def flock2(lock_file: str) -> FileLock:28 """Second file lock pointing to the same lock for testing."""29 return FileLock(lock_file)30@pytest.fixture31def frlock(lock_file: str) -> FileLock:32 """Reentrant file lock."""33 return FileLock(lock_file, reentrant=True)34@pytest.fixture35def pool() -> Yields[ThreadPoolExecutor]:36 """Thread pool with 100 maximum concurrent tasks."""37 with ThreadPoolExecutor(100) as pool:38 yield pool39def test_simple(flock: FileLock) -> None:40 """41 Asserts that the lock is locked in a context statement and that the42 return value of __enter__() is the lock.43 """44 with flock as lock:45 assert flock.is_locked46 assert flock is lock47 assert not flock.is_locked48def test_acquire_ctx(flock: FileLock) -> None:49 """Same as test_simple but using acquire_ctx."""50 with flock.acquire_ctx() as lock:51 assert flock.is_locked52 assert lock is None53 assert not flock.is_locked54def test_nested(frlock: FileLock) -> None:55 """56 Asserts that the reentrant lock is not released before the most57 outer with statement that locked the lock, is left.58 """59 with frlock as l1:60 assert frlock.is_locked61 assert frlock is l162 with frlock as l2:63 assert frlock.is_locked64 assert frlock is l265 with frlock as l3:66 assert frlock.is_locked67 assert frlock is l368 assert frlock.is_locked69 assert frlock.is_locked70 assert not frlock.is_locked71def test_nested_explicit_acquire(frlock: FileLock) -> None:72 """73 The same as test_nested, but uses the acquire() and release()74 directly rather than context managers.75 """76 assert frlock.acquire()77 assert frlock.is_locked78 assert frlock.acquire()79 assert frlock.is_locked80 assert frlock.acquire()81 assert frlock.is_locked82 frlock.release()83 assert frlock.is_locked84 frlock.release()85 assert frlock.is_locked86 frlock.release()87 assert not frlock.is_locked88def test_nested_forced_release(frlock: FileLock) -> None:89 """90 Acquires the lock using a context manager and then again inside and91 releases it before leaving.92 """93 with frlock:94 assert frlock.is_locked95 frlock.acquire()96 assert frlock.is_locked97 frlock.release(force=True)98 assert not frlock.is_locked99 assert not frlock.is_locked100def test_threaded(flock: FileLock, pool: ThreadPoolExecutor) -> None:101 """102 Runs 250 threads, which need the filelock. The lock must be acquired103 by all threads and released once all are done.104 """105 def get_lock_repeatedly(count: int) -> None:106 for _ in range(count):107 with flock:108 assert flock.is_locked109 pool.map(get_lock_repeatedly, repeat(100, 250))110 assert not flock.is_locked111def test_threaded_duplicate_lock(flock: FileLock,112 flock2: FileLock,113 pool: ThreadPoolExecutor) -> None:114 """115 Runs multiple threads, which acquire the same lock file with116 different FileLock objects. When lock1 is held, lock2 must not be117 held and vice versa.118 """119 def acquire_lock1() -> None:120 for _ in range(100):121 with flock:122 assert flock.is_locked123 assert not flock2.is_locked124 def acquire_lock2() -> None:125 for _ in range(100):126 with flock2:127 assert not flock.is_locked128 assert flock2.is_locked129 def acquire_lock(which: int) -> None:130 acquire_lock1() if which == 1 else acquire_lock2()131 pool.map(acquire_lock, chain.from_iterable(repeat((1, 2), 250)))132 assert not flock.is_locked133 assert not flock2.is_locked134def test_nonblocking(flock: FileLock) -> None:135 """136 Verify lock is not acquired with blocking=False and acquire returns137 False.138 """139 flock.acquire()140 assert flock.is_locked141 assert not flock.acquire(blocking=False)142 assert flock.is_locked143 flock.release()144 assert not flock.is_locked145def test_nonblocking_multiple_locks(flock: FileLock, flock2: FileLock) -> None:146 """Same as test_nonblocking but with multiple file locks."""147 flock.acquire()148 assert flock.is_locked149 assert not flock2.acquire(blocking=False)150 assert flock.is_locked151 assert not flock2.is_locked152 flock.release()153 assert not flock.is_locked154def test_timeout(flock: FileLock) -> None:155 """Verify lock is not acquired on timeout and acquire returns False."""156 flock.acquire()157 assert flock.is_locked158 assert not flock.acquire(timeout=0.1)159 assert flock.is_locked160 flock.release()161 assert not flock.is_locked162def test_timeout_different_locks(flock: FileLock, flock2: FileLock) -> None:163 """164 Same as test_timeout but with two different locks pointing to the165 same file.166 """167 flock.acquire()168 assert flock.is_locked169 assert not flock2.is_locked170 assert not flock2.acquire(timeout=0.1)171 assert flock.is_locked172 assert not flock2.is_locked173 flock.release()174 assert not flock.is_locked175 assert not flock2.is_locked176def test_default_timeout(lock_file: str, flock: FileLock) -> None:177 """Test if the default timeout parameter works."""178 flock_to = FileLock(lock_file, timeout=0.1)179 assert flock_to.timeout == 0.1180 flock.acquire()181 assert flock.is_locked182 assert not flock_to.is_locked183 assert not flock_to.acquire()184 assert flock.is_locked185 assert not flock_to.is_locked186 flock_to.timeout = 0187 assert not flock_to.acquire()188 assert flock.is_locked189 assert not flock_to.is_locked190 flock.release()191 assert not flock.is_locked192 assert not flock_to.is_locked193def test_timeout_acquire_ctx(flock: FileLock) -> None:194 """Test TimeoutError is raised when acquire_ctx can't acquire the lock."""195 flock.acquire()196 with pytest.raises(TimeoutError):197 with flock.acquire_ctx(timeout=0.1):198 pass199 flock.release()200def test_context_exception(flock: FileLock) -> None:201 """202 Verify filelock is released if an exception is raised when used in a203 context.204 """205 try:206 with flock:207 raise BaseException208 except BaseException: # noqa209 assert not flock.is_locked210def test_context_exception_acquire_ctx(flock: FileLock) -> None:211 """The same as test_context_exception, but uses the acquire_ctx."""212 try:213 with flock.acquire_ctx():214 raise BaseException215 except BaseException: # noqa216 assert not flock.is_locked217def test_del(lock_file: str, flock: FileLock) -> None:218 """Verify lock is released during garbage collection."""219 tmp_flock = FileLock(lock_file)220 tmp_flock.acquire()221 assert tmp_flock.is_locked222 assert not flock.is_locked223 assert not flock.acquire(timeout=0.1)224 del tmp_flock225 gc.collect() # Ensure gc runs, PyPy doesn't invoke it on del226 assert flock.acquire(timeout=1)227 assert flock.is_locked228 flock.release()...
test_aioredlock.py
Source:test_aioredlock.py
...15 ]16class TestAioredlock:17 async def check_simple_lock(self, lock_manager):18 resource = str(uuid.uuid4())19 assert await lock_manager.is_locked(resource) is False20 lock = await lock_manager.lock(resource)21 assert lock.valid is True22 assert await lock_manager.is_locked(resource) is True23 await lock_manager.extend(lock)24 assert lock.valid is True25 assert await lock_manager.is_locked(resource) is True26 await lock_manager.unlock(lock)27 assert lock.valid is False28 assert await lock_manager.is_locked(resource) is False29 await lock_manager.destroy()30 async def check_two_locks_on_different_resources(self, lock_manager):31 resource1 = str(uuid.uuid4())32 resource2 = str(uuid.uuid4())33 assert await lock_manager.is_locked(resource1) is False34 assert await lock_manager.is_locked(resource2) is False35 lock1 = await lock_manager.lock(resource1)36 assert lock1.valid is True37 assert await lock_manager.is_locked(resource1) is True38 assert await lock_manager.is_locked(resource2) is False39 lock2 = await lock_manager.lock(resource2)40 assert lock2.valid is True41 assert await lock_manager.is_locked(resource1) is True42 assert await lock_manager.is_locked(resource2) is True43 await lock_manager.unlock(lock1)44 assert lock1.valid is False45 assert await lock_manager.is_locked(resource1) is False46 await lock_manager.unlock(lock2)47 assert lock2.valid is False48 assert await lock_manager.is_locked(resource2) is False49 await lock_manager.destroy()50 async def check_two_locks_on_same_resource(self, lock_manager):51 resource = str(uuid.uuid4())52 assert await lock_manager.is_locked(resource) is False53 lock1 = await lock_manager.lock(resource)54 assert lock1.valid is True55 assert await lock_manager.is_locked(resource) is True56 with pytest.raises(LockError):57 await lock_manager.lock(resource)58 assert await lock_manager.is_locked(resource) is True59 await lock_manager.unlock(lock1)60 assert lock1.valid is False61 assert await lock_manager.is_locked(resource) is False62 await asyncio.sleep(0.2) # wait for lock cleanup63 await lock_manager.destroy()64 @pytest.mark.asyncio65 async def test_simple_aioredlock_one_instance(66 self,67 redis_one_connection):68 await self.check_simple_lock(Aioredlock(redis_one_connection))69 @pytest.mark.asyncio70 async def test_aioredlock_two_locks_on_different_resources_one_instance(71 self,72 redis_one_connection):73 await self.check_two_locks_on_different_resources(Aioredlock(redis_one_connection))74 @pytest.mark.asyncio75 async def test_aioredlock_two_locks_on_same_resource_one_instance(...
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!!