def main(): try: options = config.Options(sys.argv[1:], command_line=True) except utils.UsageError as e: print(str(e), file=sys.stderr) sys.exit(1) if options.show_config: print(options) sys.exit(0) if options.version: print(io.get_pytype_version()) sys.exit(0) node.SetCheckPreconditions(options.check_preconditions) if options.timeout is not None: signal.alarm(options.timeout) with _ProfileContext(options.profile): with metrics.MetricsContext(options.metrics, options.open_function): with metrics.StopWatch("total_time"): with metrics.Snapshot("memory", enabled=options.memory_snapshots): return _run_pytype(options)
def test_enabled(self): with tempfile.NamedTemporaryFile() as out: out.close() with metrics.MetricsContext(out.name): self._counter.inc() self.assertEqual(1, self._counter._total) with open(out.name) as f: dumped = metrics.load(f) self.assertEqual(len(dumped), 1) self.assertEqual("foo", dumped[0].name) self.assertEqual("foo: 1", str(dumped[0]))
def test_disabled(self): with metrics.MetricsContext(""): self._counter.inc() self.assertEqual(0, self._counter._total)