Skip to content

Commit f4a5408

Browse files
committed
Cleanup tools/file_packager.py and its output. NFC
- Use enumerate() to avoid a counter - (mostly) Fix indentation of generated JS
1 parent 583000b commit f4a5408

File tree

2 files changed

+112
-127
lines changed

2 files changed

+112
-127
lines changed

tests/test_other.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,25 +2497,41 @@ def test_file_packager(self):
24972497
os.chdir('subdir')
24982498
create_file('data2.txt', 'data2')
24992499

2500+
def check(text):
2501+
self.assertGreater(len(text), 0)
2502+
empty_lines = 0
2503+
# check the generated is relatively tidy
2504+
for line in text.splitlines():
2505+
if line and line[-1].isspace():
2506+
self.fail('output contains trailing whitespace: `%s`' % line)
2507+
2508+
if line.strip():
2509+
empty_lines = 0
2510+
else:
2511+
empty_lines += 1
2512+
if empty_lines > 1:
2513+
self.fail('output contains more then one empty line in row')
2514+
25002515
# relative path to below the current dir is invalid
25012516
stderr = self.expect_fail([FILE_PACKAGER, 'test.data', '--preload', '../data1.txt'])
25022517
self.assertContained('below the current directory', stderr)
25032518

25042519
# relative path that ends up under us is cool
25052520
proc = self.run_process([FILE_PACKAGER, 'test.data', '--preload', '../subdir/data2.txt'], stderr=PIPE, stdout=PIPE)
2506-
self.assertGreater(len(proc.stdout), 0)
25072521
self.assertNotContained('below the current directory', proc.stderr)
2522+
check(proc.stdout)
25082523

25092524
# direct path leads to the same code being generated - relative path does not make us do anything different
25102525
proc2 = self.run_process([FILE_PACKAGER, 'test.data', '--preload', 'data2.txt'], stderr=PIPE, stdout=PIPE)
2511-
self.assertGreater(len(proc2.stdout), 0)
2526+
check(proc2.stdout)
25122527
self.assertNotContained('below the current directory', proc2.stderr)
25132528

25142529
def clean(txt):
25152530
lines = txt.splitlines()
25162531
lines = [l for l in lines if 'PACKAGE_UUID' not in l and 'loadPackage({' not in l]
25172532
return ''.join(lines)
25182533

2534+
25192535
self.assertTextDataIdentical(clean(proc.stdout), clean(proc2.stdout))
25202536

25212537
# verify '--separate-metadata' option produces separate metadata file

0 commit comments

Comments
 (0)