def test_table_group_unpack(self): """Tests if columns belonging to a table group are properly unpacked.""" COLUMN_GROUPS.extend( initialize_column_groups(( "--TableGroup", { "col2": "column 2", "col 1": "column 1", "col4": "COLUMN 4" }, ))) d2txt = toml_to_d2txt( "columns = [\n" " 'column 1',\n 'column 2',\n 'column 3',\n 'column 4',\n" "]\n\n" "[column_groups]\n" "--TableGroup = { col2 = 'column 2', 'col 1' = 'column 1', col4 = 'column 4' }\n\n" "[[rows]]\n" "--TableGroup = { col2 = 'bar', 'col 1' = 'foo', col4 = 45 }\n" "'column 3' = 225\n\n") self.compare_d2txt( d2txt, ["column 1", "column 2", "column 3", "column 4"], [["foo", "bar", 225, 45]], )
def test_table_group_pack(self): """Tests if columns belonging to a table group are properly packed.""" COLUMN_GROUPS.extend( initialize_column_groups(( "--TableGroup", { "col2": "column 2", "col 1": "column 1", "col4": "COLUMN 4" }, ))) d2txt = D2TXT(["column 1", "column 2", "column 3", "column 4"]) d2txt.extend([["foo", "bar", 225, 45]]) self.assertEqual( d2txt_to_toml(d2txt), "columns = [\n" " 'column 1',\n 'column 2',\n 'column 3',\n 'column 4',\n" "]\n\n" "[column_groups]\n" "--TableGroup = { col2 = 'column 2', 'col 1' = 'column 1', col4 = 'column 4' }\n\n" "[[rows]]\n" "--TableGroup = { col2 = 'bar', 'col 1' = 'foo', col4 = 45 }\n" "'column 3' = 225\n\n", )
def test_nested_group_unpack(self): """Tests if columns in multilevel groups are properly unpacked.""" COLUMN_GROUPS.extend( initialize_column_groups( [ "--ArrayOfTables", [ { "min": "RedMin", "max": "RedMax" }, { "min": "BlueMin", "max": "BlueMax" }, ], ], [ "--TableOfArrays", { "weight": ["Weight1", "Weight2", "Weight3"] } ], )) d2txt = toml_to_d2txt( "columns = [\n" " 'RedMin',\n 'BlueMin',\n 'RedMax',\n 'BlueMax',\n" " 'Weight2',\n 'Weight3',\n 'Weight1',\n 'Misc',\n" "]\n\n" "[column_groups]\n" "--ArrayOfTables = [" "{ min = 'RedMin', max = 'RedMax' }, { min = 'BlueMin', max = 'BlueMax' }" "]\n" "--TableOfArrays = { weight = ['Weight1', 'Weight2', 'Weight3'] }\n\n" "[[rows]]\n" "--ArrayOfTables = [{ min = 10, max = 'unknown' }, { min = 20, max = 100 }]\n" "--TableOfArrays = { weight = [1000, 0, 500] }\n" "Misc = 4\n\n") self.compare_d2txt( d2txt, [ "RedMin", "BlueMin", "RedMax", "BlueMax", "Weight2", "Weight3", "Weight1", "Misc", ], [[10, 20, "unknown", 100, 0, 500, 1000, 4]], )
def test_array_group_pack(self): """Tests if columns belonging to an array group are properly packed.""" COLUMN_GROUPS.extend( initialize_column_groups( ("--ArrayGroup", ("column 2", "column 1", "COLUMN 4")))) d2txt = D2TXT(["column 1", "column 2", "column 3", "column 4"]) d2txt.extend([["foo", "bar", 225, 45]]) self.assertEqual( d2txt_to_toml(d2txt), "columns = [\n" " 'column 1',\n 'column 2',\n 'column 3',\n 'column 4',\n" "]\n\n" "[column_groups]\n" "--ArrayGroup = ['column 2', 'column 1', 'column 4']\n\n" "[[rows]]\n" "--ArrayGroup = ['bar', 'foo', '45']\n" "'column 3' = 225\n\n", )
def test_array_group_unpack(self): """Tests if columns belonging to an array group are properly unpacked.""" COLUMN_GROUPS.extend( initialize_column_groups( ("--ArrayGroup", ("column 2", "column 1", "COLUMN 4")))) d2txt = toml_to_d2txt( "columns = [\n" " 'column 1',\n 'column 2',\n 'column 3',\n 'column 4',\n" "]\n\n" "[column_groups]\n" "--ArrayGroup = ['column 2', 'column 1', 'column 4']\n\n" "[[rows]]\n" "--ArrayGroup = ['bar', 'foo', '45']\n" "'column 3' = 225\n\n", ) self.compare_d2txt( d2txt, ["column 1", "column 2", "column 3", "column 4"], [["foo", "bar", 225, "45"]], )