Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdfa9c93

Browse files
committed
refactor: cleanup some tests
1 parentc679095 commitdfa9c93

File tree

3 files changed

+40
-46
lines changed

3 files changed

+40
-46
lines changed

‎pyproject.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ disable = [
4343
"too-many-nested-blocks",
4444
"too-many-positional-arguments",
4545
"too-many-statements",
46-
"unspecified-encoding",
4746
]
4847

4948
[tool.pylint.typecheck]

‎src/ffpuppet/test_ffpuppet.py‎

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -465,33 +465,28 @@ def test_ffpuppet_20(tmp_path):
465465
assertffp._logs.pathisnotNone
466466
test_logs= [ffp._logs.path/f"{ffp._logs.PREFIX_SAN}.{i}"foriinrange(4)]
467467
# ignore benign ASan warning
468-
withtest_logs[0].open("w")aslog_fp:
469-
log_fp.write("==123==WARNING: Symbolizer buffer too small")
468+
test_logs[0].write_text("==123==WARNING: Symbolizer buffer too small")
470469
assertffp.is_healthy()
471470
# small log with nothing interesting
472-
withtest_logs[1].open("w")aslog_fp:
473-
log_fp.write("SHORT LOG\n")
474-
log_fp.write("filler line")
475-
# crash on another thread
476-
withtest_logs[2].open("w")aslog_fp:
477-
log_fp.write("GOOD LOG\n")
478-
log_fp.write(
479-
"==70811==ERROR: AddressSanitizer:"
480-
" SEGV on unknown address 0x00000BADF00D"
481-
" (pc 0x7f4c0bb54c67 bp 0x7f4c07bea380 sp 0x7f4c07bea360 T0)\n"
482-
)# must be 2nd line
483-
for_inrange(4):# pad out to 6 lines
484-
log_fp.write("filler line\n")
471+
test_logs[1].write_text("SHORT LOG\nfiller line")
472+
# crash on another thread (error log must start on 2nd line)
473+
test_logs[2].write_text(
474+
"GOOD LOG\n"
475+
"==70811==ERROR: AddressSanitizer: SEGV on unknown address 0x00000BADF00D "
476+
"(pc 0x7f4c0bb54c67 bp 0x7f4c07bea380 sp 0x7f4c07bea360 T0)\n"
477+
# pad out to 6 lines
478+
"filler line\nfiller line\nfiller line\n"
479+
"filler line\nfiller line\nfiller line\n"
480+
)
485481
# child log that should be ignored (created when parent crashes)
486-
withtest_logs[3].open("w")aslog_fp:
487-
log_fp.write("BAD LOG\n")
488-
log_fp.write(
489-
"==70811==ERROR: AddressSanitizer:"
490-
" SEGV on unknown address 0x000000000000"
491-
" (pc 0x7f4c0bb54c67 bp 0x7f4c07bea380 sp 0x7f4c07bea360 T2)\n"
492-
)# must be 2nd line
493-
for_inrange(4):# pad out to 6 lines
494-
log_fp.write("filler line\n")
482+
test_logs[3].write_text(
483+
"BAD LOG\n"
484+
"==70811==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 "
485+
"(pc 0x7f4c0bb54c67 bp 0x7f4c07bea380 sp 0x7f4c07bea360 T2)\n"
486+
# pad out to 6 lines
487+
"filler line\nfiller line\nfiller line\n"
488+
"filler line\nfiller line\nfiller line\n"
489+
)
495490
assertnotffp.is_healthy()
496491
assertffp.is_running()
497492
# close fake browser process before calling close to avoid hang
@@ -504,15 +499,15 @@ def test_ffpuppet_20(tmp_path):
504499
assertlen(logfiles)==6
505500
forlogfileinlogfiles:
506501
if"log_ffp_asan_"notinstr(logfile):
507-
assertlogfile.namein("log_stderr.txt","log_stdout.txt")
502+
assertlogfile.namein{"log_stderr.txt","log_stdout.txt"}
508503
continue
509504
withlogfile.open("r")aslog_fp:
510-
assertlog_fp.readline()in(
505+
assertlog_fp.readline()in{
511506
"BAD LOG\n",
512507
"GOOD LOG\n",
513508
"SHORT LOG\n",
514509
"==123==WARNING: Symbolizer buffer too small",
515-
)
510+
}
516511
assertnotany(f.is_file()forfintest_logs)
517512

518513

@@ -856,13 +851,12 @@ def test_ffpuppet_28():
856851
withFFPuppet()asffp:
857852
ffp.launch(TESTFF_BIN)
858853
assertffp._logs.pathisnotNone
859-
san_log=f"{ffp._logs.path/ffp._logs.PREFIX_SAN}.1"
854+
san_log=ffp._logs.path/f"{ffp._logs.PREFIX_SAN}.1"
860855
assertnotffp._logs.watching
861856
# ignore benign ASan warning
862-
withopen(san_log,"w")aslog_fp:
863-
log_fp.write("==123==WARNING: Symbolizer buffer too small")
857+
san_log.write_text("==123==WARNING: Symbolizer buffer too small")
864858
assertffp.is_healthy()
865-
assertsan_loginffp._logs.watching
859+
assertstr(san_log)inffp._logs.watching
866860
ffp.close()
867861
assertffp.reason==Reason.CLOSED
868862

‎src/ffpuppet/test_puppet_logger.py‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"""ffpuppet puppet logger tests"""
55
# pylint: disable=protected-access
66

7-
importos
7+
fromosimportstat
8+
fromos.pathimportisfile
89
fromtempfileimportSpooledTemporaryFile
910
fromtimeimportsleep
1011

@@ -20,10 +21,10 @@ def test_puppet_logger_01(tmp_path):
2021
assertnotplog._logs
2122
assertplog.pathisnotNone
2223
assertplog.path.is_dir()
23-
assertplog._baseisnotNone
24-
assertany(os.scandir(plog._base))
24+
assertplog._base==str(tmp_path)
25+
assertany(tmp_path.iterdir())
2526
plog.close()
26-
assertany(os.scandir(plog._base))
27+
assertany(tmp_path.iterdir())
2728
assertplog.closed
2829
withraises(AssertionError):
2930
plog.add_log("test")
@@ -40,15 +41,15 @@ def test_puppet_logger_02(tmp_path):
4041
assert"test_new"inplog.available_logs()
4142
plog_fp_test_new=plog.get_fp("test_new")
4243
assertplog_fp_test_newisnotNone
43-
assertos.path.isfile(plog_fp_test_new.name)
44+
assertisfile(plog_fp_test_new.name)
4445
with (tmp_path/"test_existing.txt").open("w+b")asin_fp:
4546
in_fp.write(b"blah")
4647
plog.add_log("test_existing",logfp=in_fp)
4748
assertlen(plog.available_logs())==2
4849
assertlen(tuple(plog.files))==2
4950
plog_fp_test_existing=plog.get_fp("test_existing")
5051
assertplog_fp_test_existingisnotNone
51-
assertos.path.isfile(plog_fp_test_existing.name)
52+
assertisfile(plog_fp_test_existing.name)
5253
assertplog.log_length("test_new")==0
5354
assertplog.log_length("test_existing")==4
5455

@@ -60,12 +61,12 @@ def test_puppet_logger_03(tmp_path):
6061
assertnotplog._logs
6162
assertplog.pathisnotNone
6263
assertplog.path.is_dir()
63-
assertplog._baseisnotNone
64-
assertany(os.scandir(plog._base))
64+
assertplog._base==str(tmp_path)
65+
assertany(tmp_path.iterdir())
6566
plog.add_log("test_new")
6667
plog.clean_up()
6768
assertplog.closed
68-
assertnotany(os.scandir(plog._base))
69+
assertnotany(tmp_path.iterdir())
6970
assertplog.pathisNone
7071
assertplog.closed
7172
assertnotplog._logs
@@ -81,8 +82,8 @@ def test_puppet_logger_04(tmp_path):
8182
assertnotplog._logs
8283
assertplog.pathisnotNone
8384
assertplog.path.is_dir()
84-
assertplog._baseisnotNone
85-
assertlen(os.listdir(plog._base))==1
85+
assertplog._base==str(tmp_path)
86+
assertlen(tuple(tmp_path.iterdir()))==1
8687

8788

8889
deftest_puppet_logger_05(tmp_path):
@@ -173,9 +174,9 @@ def test_puppet_logger_06(tmp_path):
173174
assertlen(plog.available_logs())==4
174175
assertlen(tuple(dest.iterdir()))==4
175176
# verify all data was copied
176-
assertos.stat(plog_fp_test_1.name).st_size==12
177-
assertos.stat(plog_fp_test_2.name).st_size==7
178-
assertos.stat(plog_fp_test_3.name).st_size==500*1234
177+
assertstat(plog_fp_test_1.name).st_size==12
178+
assertstat(plog_fp_test_2.name).st_size==7
179+
assertstat(plog_fp_test_3.name).st_size==500*1234
179180

180181

181182
deftest_puppet_logger_07(mocker,tmp_path):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp