Skip to content

Commit

Permalink
Adapt string replacement of WARC content for tests to use bytes for #608
Browse files Browse the repository at this point in the history
  • Loading branch information
machawk1 committed Jun 1, 2019
1 parent 7ffb482 commit cd6fa76
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/testUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ def createUniqueWARC():
warcInPath = os.path.join(os.path.dirname(__file__) +
'/../samples/warcs/' + warcInFilename)

stringToChange = 'abcdefghijklmnopqrstuvwxz'
stringToChange = b'abcdefghijklmnopqrstuvwxz'
randomString = getRandomString(len(stringToChange))
randomBytes = str.encode(randomString)

with open(warcInPath, 'r') as warcFile:
newContent = warcFile.read().decode('utf-8').replace(stringToChange, randomString)
with open(warcInPath, 'rb') as warcFile:
newContent = warcFile.read().replace(stringToChange, randomBytes)

warcOutFilename = warcInFilename.replace('.warc', '_' +
randomString + '.warc')
warcOutPath = os.path.join(os.path.dirname(__file__) +
'/../samples/warcs/' + warcOutFilename)
with open(warcOutPath, 'w') as warcFile:
print(warcOutPath)
with open(warcOutPath, 'wb') as warcFile:
warcFile.write(newContent)

return warcOutPath
Expand Down

0 comments on commit cd6fa76

Please sign in to comment.