本文整理汇总了Python中outputty.Table.extend方法的典型用法代码示例。如果您正苦于以下问题:Python Table.extend方法的具体用法?Python Table.extend怎么用?Python Table.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类outputty.Table
的用法示例。
在下文中一共展示了Table.extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_table_append_column_should_raise_ValueError_when_wrong_size
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_append_column_should_raise_ValueError_when_wrong_size(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6]])
with self.assertRaises(ValueError):
table.append_column("new column", [3, 5, 7, 8])
self.assertEquals(table.headers, ["python", "rules"])
self.assertEquals(table[:], [[1, 2], [3, 4], [5, 6]])
示例2: test_table_extend_should_add_nothing_if_an_exception_is_raised
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_extend_should_add_nothing_if_an_exception_is_raised(self):
table = Table(headers=["spam", "eggs"])
table.append(["hello", "world"])
with self.assertRaises(ValueError):
table.extend([["python", "rules"], ["answer", 42], [1, 2, 3]])
self.assertEquals(table[0], ["hello", "world"])
self.assertEquals(len(table), 1)
示例3: test_append_column_should_raise_ValueError_when_column_already_exists
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_append_column_should_raise_ValueError_when_column_already_exists(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6]])
with self.assertRaises(ValueError):
table.append_column("python", [3, 5, 7])
self.assertEquals(table.headers, ["python", "rules"])
self.assertEquals(table[:], [[1, 2], [3, 4], [5, 6]])
示例4: test_table_remove
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_remove(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6], [1, 2]])
table.remove({"python": 3, "rules": 4})
self.assertEquals(table[:], [[1, 2], [5, 6], [1, 2]])
table.remove([1, 2])
self.assertEquals(table[:], [[5, 6], [1, 2]])
示例5: test_table_insert
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_insert(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6], [7, 8], [1, 2]])
table.insert(0, [4, 2])
table.insert(1, {"python": 9, "rules": 9})
self.assertEquals(table[0], [4, 2])
self.assertEquals(table[1], [9, 9])
self.assertEquals(len(table), 7)
示例6: test_table_should_be_a_sequence
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_should_be_a_sequence(self):
table = Table(headers=["spam", "eggs"])
table.extend([["python", "rules"], ["answer", 42]])
items = []
for item in table:
items.append(item)
self.assertEquals(items[0], ["python", "rules"])
self.assertEquals(items[1], ["answer", 42])
示例7: test_table_set_item_should_work_for_column
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_set_item_should_work_for_column(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6]])
table["python"] = [2, 4, 6]
self.assertEquals(table[:], [[2, 2], [4, 4], [6, 6]])
with self.assertRaises(KeyError):
should_raise_exception = table["not-found"]
with self.assertRaises(ValueError):
table["rules"] = [1, 2, 3, 4]
示例8: test_table_index
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_index(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4], [5, 6], [7, 8], [1, 2], [9, 0]])
self.assertEquals(table.index([1, 2]), 0)
self.assertEquals(table.index({"python": 1, "rules": 2}), 0)
self.assertEquals(table.index([5, 6]), 2)
self.assertEquals(table.index([1, 2], 1), 4)
with self.assertRaises(ValueError):
non_ecxiste = table.index([1, 9])
with self.assertRaises(ValueError):
not_found = table.index([1, 2], 1, 3)
示例9: test_ordering_ascending
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_ordering_ascending(self):
table = Table(headers=["spam"])
table.extend([[5], [3], [7], [10]])
table.order_by("spam", "ascending")
table_2 = Table(headers=["spam"])
table_2.extend([[5], [3], [7], [10]])
table_2.order_by("spam", "asc")
table_3 = Table(headers=["spam"])
table_3.extend([[5], [3], [7], [10]])
table_3.order_by("spam", "ASCENDING")
table_4 = Table(headers=["spam"])
table_4.extend([[5], [3], [7], [10]])
table_4.order_by("spam", "ASC")
expected_output = dedent(
"""
+------+
| spam |
+------+
| 3 |
| 5 |
| 7 |
| 10 |
+------+
"""
).strip()
self.assertEqual(str(table), expected_output)
self.assertEqual(str(table_2), expected_output)
示例10: test_table_set_item_should_work_for_rows
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_table_set_item_should_work_for_rows(self):
table = Table(headers=["python", "rules"])
table.append([1, 2])
table[0] = [4, 2]
self.assertEquals(table[:], [[4, 2]])
table.extend([[3, 4], [5, 6]])
table[1:] = [[7, 8], [9, 0]]
self.assertEquals(table[:], [[4, 2], [7, 8], [9, 0]])
table[-3:] = [[5, 5], [7, 7], [9, 9]]
self.assertEquals(table[:], [[5, 5], [7, 7], [9, 9]])
with self.assertRaises(ValueError):
table[1] = [1, 2, 3]
with self.assertRaises(ValueError):
table[(1, 2)] = [1, 2]
示例11: test_append_column_should_accept_a_function_to_create_new_column
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_append_column_should_accept_a_function_to_create_new_column(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4]])
table.append_column("new column", lambda row: row[0] + row[1])
self.assertEquals(table.headers, ["python", "rules", "new column"])
self.assertEquals(table[:], [[1, 2, 3], [3, 4, 7]])
del table["new column"]
table.append_column("other column", lambda row: row[0] + row[1], position=0)
self.assertEquals(table.headers, ["other column", "python", "rules"])
self.assertEquals(table[:], [[3, 1, 2], [7, 3, 4]])
del table["other column"]
table.append_column("third column", lambda r: r["python"] * r["rules"], row_as_dict=True)
self.assertEquals(table.headers, ["python", "rules", "third column"])
self.assertEquals(table[:], [[1, 2, 2], [3, 4, 12]])
示例12: test_vertical_histogram
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_vertical_histogram(self):
seed(1234) # Setting the seed to get repeatable results
numbers = normal(size=1000)
my_table = Table(headers=['values'])
my_table.extend([[value] for value in numbers])
output = my_table.write('histogram', column='values', height=5,
orientation='vertical', bins=10)
expected = dedent('''
265 |
||
|||
||||
||||||
-3.56 2.76
''').strip()
self.assertEquals(output, expected)
示例13: test_order_by_method_should_order_ascending_by_default
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_order_by_method_should_order_ascending_by_default(self):
table = Table(headers=["spam"])
table.extend([[5], [3], [7], [10]])
table.order_by("spam")
expected_output = dedent(
"""
+------+
| spam |
+------+
| 3 |
| 5 |
| 7 |
| 10 |
+------+
"""
).strip()
self.assertEqual(str(table), expected_output)
示例14: test_horizontal_histogram
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_horizontal_histogram(self):
seed(1234) # Setting the seed to get repeatable results
numbers = normal(size=1000)
my_table = Table(headers=['values'])
my_table.extend([[value] for value in numbers])
output = my_table.write('histogram', column='values', height=15, bins=10,
orientation='horizontal')
expected = dedent('''\
265
-3.56:
-2.93:
-2.30: ||
-1.67: ||||
-1.03: ||||||||||
-0.40: |||||||||||||||
0.23 : ||||||||||||
0.87 : ||||||
1.50 : |||
2.13 :''')
self.assertEquals(output, expected)
示例15: test_append_column_should_be_inserted_in_any_position
# 需要导入模块: from outputty import Table [as 别名]
# 或者: from outputty.Table import extend [as 别名]
def test_append_column_should_be_inserted_in_any_position(self):
table = Table(headers=["python", "rules"])
table.extend([[1, 2], [3, 4]])
table.append_column("new column", [3, 5], position=0)
self.assertEquals(table.headers, ["new column", "python", "rules"])
self.assertEquals(table[:], [[3, 1, 2], [5, 3, 4]])