Mercurial > hg
comparison tests/run-tests.py @ 49306:2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Tue, 31 May 2022 22:50:01 +0200 |
parents | 53e9422a9b45 |
children | 35bf7f23b84c |
comparison
equal
deleted
inserted
replaced
49305:53e9422a9b45 | 49306:2e726c934fcd |
---|---|
360 entries = dict() | 360 entries = dict() |
361 for filename in files: | 361 for filename in files: |
362 try: | 362 try: |
363 path = os.path.expanduser(os.path.expandvars(filename)) | 363 path = os.path.expanduser(os.path.expandvars(filename)) |
364 f = open(path, "rb") | 364 f = open(path, "rb") |
365 except IOError as err: | 365 except FileNotFoundError: |
366 if err.errno != errno.ENOENT: | |
367 raise | |
368 if warn: | 366 if warn: |
369 print("warning: no such %s file: %s" % (listtype, filename)) | 367 print("warning: no such %s file: %s" % (listtype, filename)) |
370 continue | 368 continue |
371 | 369 |
372 for line in f.readlines(): | 370 for line in f.readlines(): |
388 try: | 386 try: |
389 with open(path, 'rb') as f: | 387 with open(path, 'rb') as f: |
390 for l in f: | 388 for l in f: |
391 if l.startswith(b'#testcases '): | 389 if l.startswith(b'#testcases '): |
392 cases.append(sorted(l[11:].split())) | 390 cases.append(sorted(l[11:].split())) |
393 except IOError as ex: | 391 except FileNotFoundError: |
394 if ex.errno != errno.ENOENT: | 392 pass |
395 raise | |
396 return cases | 393 return cases |
397 | 394 |
398 | 395 |
399 def getparser(): | 396 def getparser(): |
400 """Obtain the OptionParser used by the CLI.""" | 397 """Obtain the OptionParser used by the CLI.""" |
1108 | 1105 |
1109 # Remove any previous output files. | 1106 # Remove any previous output files. |
1110 if os.path.exists(self.errpath): | 1107 if os.path.exists(self.errpath): |
1111 try: | 1108 try: |
1112 os.remove(self.errpath) | 1109 os.remove(self.errpath) |
1113 except OSError as e: | 1110 except FileNotFoundError: |
1114 # We might have raced another test to clean up a .err | 1111 # We might have raced another test to clean up a .err file, |
1115 # file, so ignore ENOENT when removing a previous .err | 1112 # so ignore FileNotFoundError when removing a previous .err |
1116 # file. | 1113 # file. |
1117 if e.errno != errno.ENOENT: | 1114 pass |
1118 raise | |
1119 | 1115 |
1120 if self._usechg: | 1116 if self._usechg: |
1121 self._chgsockdir = os.path.join( | 1117 self._chgsockdir = os.path.join( |
1122 self._threadtmp, b'%s.chgsock' % name | 1118 self._threadtmp, b'%s.chgsock' % name |
1123 ) | 1119 ) |
2620 for line in fp: | 2616 for line in fp: |
2621 m = re.match('(.*?) ([0-9. ]+)', line) | 2617 m = re.match('(.*?) ([0-9. ]+)', line) |
2622 times.append( | 2618 times.append( |
2623 (m.group(1), [float(t) for t in m.group(2).split()]) | 2619 (m.group(1), [float(t) for t in m.group(2).split()]) |
2624 ) | 2620 ) |
2625 except IOError as err: | 2621 except FileNotFoundError: |
2626 if err.errno != errno.ENOENT: | 2622 pass |
2627 raise | |
2628 return times | 2623 return times |
2629 | 2624 |
2630 | 2625 |
2631 def savetimes(outputdir, result): | 2626 def savetimes(outputdir, result): |
2632 saved = dict(loadtimes(outputdir)) | 2627 saved = dict(loadtimes(outputdir)) |
2977 try: | 2972 try: |
2978 return perf[f] | 2973 return perf[f] |
2979 except KeyError: | 2974 except KeyError: |
2980 try: | 2975 try: |
2981 val = -os.stat(f).st_size | 2976 val = -os.stat(f).st_size |
2982 except OSError as e: | 2977 except FileNotFoundError: |
2983 if e.errno != errno.ENOENT: | |
2984 raise | |
2985 perf[f] = -1e9 # file does not exist, tell early | 2978 perf[f] = -1e9 # file does not exist, tell early |
2986 return -1e9 | 2979 return -1e9 |
2987 for kw, mul in slow.items(): | 2980 for kw, mul in slow.items(): |
2988 if kw in f: | 2981 if kw in f: |
2989 val *= mul | 2982 val *= mul |
3582 mypython = os.path.join(self._custom_bin_dir, pyexename) | 3575 mypython = os.path.join(self._custom_bin_dir, pyexename) |
3583 try: | 3576 try: |
3584 if os.readlink(mypython) == sysexecutable: | 3577 if os.readlink(mypython) == sysexecutable: |
3585 continue | 3578 continue |
3586 os.unlink(mypython) | 3579 os.unlink(mypython) |
3587 except OSError as err: | 3580 except FileNotFoundError: |
3588 if err.errno != errno.ENOENT: | 3581 pass |
3589 raise | |
3590 if self._findprogram(pyexename) != sysexecutable: | 3582 if self._findprogram(pyexename) != sysexecutable: |
3591 try: | 3583 try: |
3592 os.symlink(sysexecutable, mypython) | 3584 os.symlink(sysexecutable, mypython) |
3593 self._createdfiles.append(mypython) | 3585 self._createdfiles.append(mypython) |
3594 except FileExistsError: | 3586 except FileExistsError: |
3712 vlog("# Running", cmd.decode("utf-8")) | 3704 vlog("# Running", cmd.decode("utf-8")) |
3713 if subprocess.call(_bytes2sys(cmd), shell=True) == 0: | 3705 if subprocess.call(_bytes2sys(cmd), shell=True) == 0: |
3714 if not self.options.verbose: | 3706 if not self.options.verbose: |
3715 try: | 3707 try: |
3716 os.remove(installerrs) | 3708 os.remove(installerrs) |
3717 except OSError as e: | 3709 except FileNotFoundError: |
3718 if e.errno != errno.ENOENT: | 3710 pass |
3719 raise | |
3720 else: | 3711 else: |
3721 with open(installerrs, 'rb') as f: | 3712 with open(installerrs, 'rb') as f: |
3722 for line in f: | 3713 for line in f: |
3723 sys.stdout.buffer.write(line) | 3714 sys.stdout.buffer.write(line) |
3724 sys.exit(1) | 3715 sys.exit(1) |