Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_start(self):
options = ScourOptions
input = open('unittests/minimal.svg', 'rb')
output = open('testscour_temp.svg', 'wb')
stdout_temp = sys.stdout
sys.stdout = None
try:
start(options, input, output)
fail = False
except Exception:
fail = True
sys.stdout = stdout_temp
os.remove('testscour_temp.svg')
self.assertEqual(fail, False,
'Exception when calling "start" with empty options object')
options.strip_xml_prolog = True
options.strip_xml_space_attribute = True
options.remove_titles = True
options.remove_descriptions = True
options.remove_metadata = True
options.remove_descriptive_elements = True
options.quiet = True
for file in files:
options.infilename = file
options.outfilename = file[:-4] + "-scoured.svg"
try:
# .start will close the files. Weird flex but ok
with open(file, 'rb') as infile, open(options.outfilename, 'wb') as outfile:
scour.start(options, infile, outfile)
except FileNotFoundError:
# Doing this because we have a list of
# hard-coded file names
print(f"File {file} not found")
except:
print("Failed to optimize:", file)
if not infile.closed: infile.close()
if not outfile.closed: outfile.close()
if Path(options.outfilename).is_file():
Path(options.outfilename).unlink()
else:
Path(options.outfilename).rename(file)