json_values_converter_tests.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2016 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Tests for json_values_converter.py.
  6. It tests json_values_converter.py.
  7. """
  8. import argparse
  9. import os
  10. import sys
  11. def CompareFiles(file1, file2):
  12. return open(file1, 'r').read() == open(file2, 'r').read()
  13. def TouchStamp(stamp_path):
  14. dir_name = os.path.dirname(stamp_path)
  15. if not os.path.isdir(dir_name):
  16. os.makedirs(dir_name)
  17. with open(stamp_path, 'a'):
  18. os.utime(stamp_path, None)
  19. def main():
  20. parser = argparse.ArgumentParser()
  21. parser.add_argument('--stamp',
  22. help='Path to touch on success.')
  23. parser.add_argument('files', nargs='+',
  24. help='Files to compare.')
  25. args = parser.parse_args()
  26. passed = True
  27. for i, j in zip(args.files[::2], args.files[1::2]):
  28. passed = passed and CompareFiles(i, j)
  29. if passed and args.stamp:
  30. TouchStamp(args.stamp)
  31. return not passed
  32. if __name__ == '__main__':
  33. sys.exit(main())