def _extract_row(slides, xls, slide_id, el, value_cell, range_name, options): log.debug(" loading from xlsx: slide_id:%s EL:%s value:%s range:%s options:%s" % (slide_id, el, value_cell.value, range_name, options)) number_format = _get_number_format_from_options(options) model_value = None if value_cell.value: model_value = _format_cell_value(value_cell) elif range_name: if range_name[0] == '=': rects = [] for one_range in range_name[1:].split(','): parts = one_range.split('!') # sheet!A1:C99 style sheet, coords = parts[0], parts[1] rects.append(xls[sheet][coords]) else: rects = [xls[sheet][coords] for sheet, coords in xls.defined_names[range_name].destinations] array_mode = u"Array" in options tsv = _build_tsv(rects, side_by_side = u"SideBySide" in options, transpose = u"Transpose" in options, format_cell = array_mode) if array_mode: model_value = tsv else: tsv_body = StringIO() _write_tsv(tsv_body, tsv) model_value = {"tsv_body": tsv_body.getvalue(), "number_format": number_format, "xy_transpose": u"XYTranspose" in options} tsv_body.close() else: raise ValueError("One of value or range_name required.") return pyel.set_value(slides, u"%s.%s" % (slide_id, el), model_value)
def test_gen_model_with_invalid_array(self): with self.assertRaises(ValueError): set_value({'greeting': [1, 2]}, 'greeting.en', 'error')
def test_gen_model_with_invalid_dict(self): with self.assertRaises(ValueError): set_value({'greeting': 'hello'}, 'greeting.0', 'error')
def test_gen_model_dict_start_with_dot(self): with self.assertRaises(ValueError): set_value({}, '.en', 'hello')
def test_gen_model_dict_add(self): result = set_value({'greeting': { 'en': 'hola' }}, 'greeting.en', 'hello') self.assertEqual(result['greeting']['en'], 'hello')
def test_gen_model_dict(self): result = set_value({}, 'greeting.en', 'hello') self.assertEqual(result['greeting']['en'], 'hello')
def test_gen_model_array_add_index_not_exist(self): result = set_value({'greeting': [1, 2]}, 'greeting.5', 'hello') self.assertEqual(result['greeting'][5], 'hello')
def test_gen_model_array_add(self): result = set_value({'greeting': []}, 'greeting.0', 'hello') self.assertEqual(result['greeting'][0], 'hello')