1
- from lxml import html
2
- from getpass import getuser
3
1
import io
4
2
import os
5
- import stat
6
3
import re
4
+ import stat
7
5
import subprocess
8
- import time
9
6
import tempfile
10
- from textwrap import wrap
7
+ import time
11
8
import unittest
9
+ from getpass import getuser
10
+ from textwrap import wrap
12
11
13
- from write_to_file import write_to_file
14
12
from book_parser import (
15
13
CodeListing ,
16
14
Command ,
17
15
Output ,
18
16
parse_listing ,
19
17
)
18
+ from lxml import html
20
19
from sourcetree import Commit , SourceTree
21
20
from update_source_repo import update_sources_for_chapter
21
+ from write_to_file import write_to_file
22
22
23
23
PHANTOMJS_RUNNER = os .path .join (
24
24
os .path .abspath (os .path .dirname (__file__ )), "my-phantomjs-qunit-runner.js"
@@ -256,9 +256,7 @@ def parse_listings(self):
256
256
257
257
def check_final_diff (self , ignore = None , diff = None ):
258
258
if diff is None :
259
- diff = self .run_command (
260
- Command ("git diff -w repo/{}" .format (self .chapter_name ))
261
- )
259
+ diff = self .run_command (Command (f"git diff -w repo/{ self .chapter_name } " ))
262
260
try :
263
261
print ("checking final diff" , diff )
264
262
except io .BlockingIOError :
@@ -269,11 +267,9 @@ def check_final_diff(self, ignore=None, diff=None):
269
267
270
268
if ignore is None :
271
269
if commit .lines_to_add :
272
- self .fail ("Found lines to add in diff:\n {}" . format ( commit .lines_to_add ) )
270
+ self .fail (f "Found lines to add in diff:\n { commit .lines_to_add } " )
273
271
if commit .lines_to_remove :
274
- self .fail (
275
- "Found lines to remove in diff:\n {}" .format (commit .lines_to_remove )
276
- )
272
+ self .fail (f"Found lines to remove in diff:\n { commit .lines_to_remove } " )
277
273
return
278
274
279
275
if "moves" in ignore :
@@ -285,7 +281,7 @@ def check_final_diff(self, ignore=None, diff=None):
285
281
for line in difference_lines :
286
282
if any (ignorable in line for ignorable in ignore ):
287
283
continue
288
- self .fail ("Found divergent line in diff:\n {}" . format ( line ) )
284
+ self .fail (f "Found divergent line in diff:\n { line } " )
289
285
290
286
def start_with_checkout (self ):
291
287
update_sources_for_chapter (self .chapter_name , self .previous_chapter )
@@ -305,7 +301,7 @@ def write_to_file(self, codelisting):
305
301
def apply_patch (self , codelisting ):
306
302
tf = tempfile .NamedTemporaryFile (delete = False )
307
303
tf .write (codelisting .contents .encode ("utf8" ))
308
- tf .write ("\n " . encode ( "utf8" ) )
304
+ tf .write (b "\n " )
309
305
tf .close ()
310
306
print ("patch:\n " , codelisting .contents )
311
307
patch_output = self .run_command (
@@ -445,9 +441,8 @@ def skip_with_check(self, pos, expected_content):
445
441
if hasattr (listing , "contents" ):
446
442
if expected_content not in listing .contents :
447
443
raise Exception (error )
448
- else :
449
- if expected_content not in listing :
450
- raise Exception (error )
444
+ elif expected_content not in listing :
445
+ raise Exception (error )
451
446
listing .skip = True
452
447
453
448
def replace_command_with_check (self , pos , old , new ):
@@ -465,7 +460,7 @@ def replace_command_with_check(self, pos, old, new):
465
460
466
461
def _run_tree (self , target = "" ):
467
462
return self .sourcetree .run_command (
468
- f"tree -v -I __pycache__ --noreport { target } " , cwd ,
463
+ f"tree -v -I __pycache__ --noreport { target } "
469
464
)
470
465
471
466
def assert_directory_tree_correct (self , expected_tree ):
@@ -855,7 +850,7 @@ def recognise_listing_and_process_it(self):
855
850
listing .was_checked = True
856
851
self .pos += 2
857
852
elif "tree" in listing and next_listing .type == "tree" :
858
- assert listing .startswith (' tree' )
853
+ assert listing .startswith (" tree" )
859
854
_ , _ , target = listing .partition ("tree" )
860
855
output = self ._run_tree (target = target )
861
856
self .assert_console_output_correct (output , next_listing )
0 commit comments