1 #!/usr/bin/python 2 3 # 4 # Copyright 2017, The Android Open Source Project 5 # 6 # Licensed under the Apache License, Version 2.0 (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 # 18 19 """ Run this script when you need to update test-data/expected.""" 20 import sys 21 22 if len(sys.argv) != 2: 23 print("You need to specify the only one param: file with test failures") 24 sys.exit() 25 26 with open(sys.argv[1]) as f: 27 content = f.readlines() 28 29 with open("src/tests/test-data/expected/license.txt") as license: 30 licenseLines = license.readlines() 31 32 33 def writeToFile(fileName, lines): 34 file = open("src/tests/test-data/expected/" + fileName, "w") 35 for line in lines: 36 file.write(line) 37 38 file.close() 39 40 41 state = 0 42 filename = "" 43 expected = "Expected file:" 44 fileLines = [] 45 for line in content: 46 if (state == 0 and line.startswith(expected)): 47 state = 1 48 filename = line[line.rfind("/") + 1 : len(line) - 2] 49 print(filename) 50 51 if state == 1 and line.startswith("Actual Source:"): 52 state = 2 53 continue 54 55 if state == 2: 56 fileLines.append(line) 57 58 if state == 2 and line.rstrip() == "}": 59 writeToFile(filename, licenseLines + fileLines[1:]) 60 state = 0 61 fileLines = [] 62 63