def test_generate_points_random_num_points(): """Test generate_points with random returns correct number of points""" param_dict = sf.read_param_ranges( os.path.join(test_files_dir, 'folder', 'test_file_1')) command = 'batch-submit 16 -m random -s' with mock.patch('sys.argv', command.split(' ')): args = get_args() _, num_points = sf.generate_points(args, param_dict) assert num_points == 16
def test_generate_points_random_ranges(): """Test generate_points with random gens points within ranges""" param_dict = sf.read_param_ranges( os.path.join(test_files_dir, 'folder', 'test_file_1')) command = 'batch-submit 16 -m random -s' with mock.patch('sys.argv', command.split(' ')): args = get_args() param_dict, num_points_ = sf.generate_points(args, param_dict) for param, info in param_dict.iteritems(): for value in info['values']: assert info['range'][0] <= value <= info['range'][1]
def test_get_args(fixture): """Test that each flag/option in parser returns expected values""" system_args = fixture[1]['command'].split(' ') try: with mock.patch('sys.argv', system_args): args = get_args() except SystemExit, system_exit: if fixture[0].startswith('invalid'): return else: # Fail if error raised on a valid input raise system_exit
def test_generate_points_uniform_num_points_input(): """Test generate_points with uniform returns correct number of points""" param_dict = sf.read_param_ranges( os.path.join(test_files_dir, 'folder', 'test_file_1')) command = 'batch-submit 10 -m uniform -s' with mock.patch('sys.argv', command.split(' ')): args = get_args() # Create mock object to replace raw_input and return 'yes' when called with mock.patch.object(__builtin__, 'raw_input', lambda x: 'yes'): _, num_points = param_dict, _ = sf.generate_points(args, param_dict) assert num_points == 16
def test_valid_arguments(fixture): """ Test that 'valid_arguments' function recognises valid and invalid args """ system_args = fixture[1]['command'].split(' ') try: with mock.patch('sys.argv', system_args): args = get_args() except SystemExit, system_exit: if fixture[0].startswith('invalid'): return else: raise system_exit
def parse_command(command): """Parse given command using parser in 'batch_submit.py'""" with mock.patch('sys.argv', command.split(' ')): args = get_args() return args