History

Merge branch 'fix/py2cmd'

Paul Brossier committed 8 years ago

Commit 9cf64622 parents 31a3fd4 eb6f9d32 files · +24 −4Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/lib/aubio/cmd.py +18 −1
  2. python/tests/test_aubio_cmd.py +6 −3
python/lib/aubio/cmd.py+18−1
@@ -499,7 +499,24 @@ class process_cut(process_onset): · 498 unmodified lines
499 499
500def main():500def main():
501 parser = aubio_parser()501 parser = aubio_parser()
502 args = parser.parse_args()502 if sys.version_info[0] != 3:
503 # on py2, create a dummy ArgumentParser to workaround the
504 # optional subcommand issue. See https://bugs.python.org/issue9253
505 # This ensures that:
506 # - version string is shown when only '-V' is passed
507 # - help is printed if '-V' is passed with any other argument
508 # - any other argument get forwarded to the real parser
509 parser_root = argparse.ArgumentParser(add_help=False)
510 parser_root.add_argument('-V', '--version', help="show version",
511 action="store_true", dest="show_version")
512 args, extras = parser_root.parse_known_args()
513 if args.show_version == False: # no -V, forward to parser
514 args = parser.parse_args(extras, namespace=args)
515 elif len(extras) != 0: # -V with other arguments, print help
516 parser.print_help()
517 sys.exit(1)
518 else: # in py3, we can simply use parser directly
519 args = parser.parse_args()
503 if 'show_version' in args and args.show_version:520 if 'show_version' in args and args.show_version:
504 sys.stdout.write('aubio version ' + aubio.version + '\n')521 sys.stdout.write('aubio version ' + aubio.version + '\n')
505 sys.exit(0)522 sys.exit(0)
python/tests/test_aubio_cmd.py+6−3
@@ -19,13 +19,16 @@ class aubio_cmd(TestCase): · 18 unmodified lines
19class aubio_cmd_utils(TestCase):19class aubio_cmd_utils(TestCase):
20 20
21 def test_samples2seconds(self):21 def test_samples2seconds(self):
22 self.assertEqual(aubio.cmd.samples2seconds(3200, 32000), "0.100000\t")22 self.assertEqual(aubio.cmd.samples2seconds(3200, 32000),
23 "0.100000\t")
23 24
24 def test_samples2milliseconds(self):25 def test_samples2milliseconds(self):
25 self.assertEqual(aubio.cmd.samples2milliseconds(3200, 32000), "100.000000\t")26 self.assertEqual(aubio.cmd.samples2milliseconds(3200, 32000),
27 "100.000000\t")
26 28
27 def test_samples2samples(self):29 def test_samples2samples(self):
28 self.assertEqual(aubio.cmd.samples2samples(3200, 32000), "3200\t")30 self.assertEqual(aubio.cmd.samples2samples(3200, 32000),
31 "3200\t")
29 32
30if __name__ == '__main__':33if __name__ == '__main__':
31 main()34 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t