def test4(self): x = optparse.OptionParser() x.add_option('-m', unit = units.MSun, help = "(unit: %unit)", default = '1.5', dest = "mass", type = float) helpstr = x.format_help() print helpstr self.assertTrue('(unit: MSun)' in helpstr) x = optparse.OptionParser() x.add_option('-m', unit = nbody_system.mass, help = "(unit: %unit)", default = '1.5', dest = "mass", type = float) helpstr = x.format_help() print helpstr self.assertTrue('(unit: mass)' in helpstr)
def test6(self): x = optparse.OptionParser() x.add_option('-m', unit = units.MSun, help = "(default: %default, unit: %unit)", default = '1.5', dest = "mass", type = float) helpstr = x.format_help() print helpstr self.assertTrue('unit: MSun)' in helpstr) self.assertTrue('(default: 1' in helpstr)
def test5(self): x = optparse.OptionParser() x.add_option('-m', unit=units.MSun, default=1.5, dest="mass", type=float) options, args = x.parse_args(['bla']) self.assertAlmostRelativeEquals(options.mass, 1.5 | units.MSun) self.assertEqual(args[0], 'bla')
def parse_options(): parser= optparse.OptionParser() parser.add_option("-i", dest="input_filename", type="string", default="test.amuse", help="The file in which the snapshots are saved [%default]") parser.add_option("-o", dest="output_filename", type="string", default="test.mp4", help="The name of the movie [%default]") options, arguments = parser.parse_args() return options.__dict__
def test1(self): x = optparse.OptionParser() x.add_option('-m', unit = units.MSun, dest = "mass", type = float) options, args = x.parse_args(['-m', '2.0']) self.assertAlmostRelativeEquals(options.mass, 2.0 | units.MSun)