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_none_or_empty_string_ignored(self): """Tests if None or '' is ignored, but other falsy values are not.""" d2txt = D2TXT(["int 0", "float 0.0", "False", "None", "empty"]) d2txt.extend([[0, 0.0, False, None, ""]]) self.assertEqual( d2txt_to_toml(d2txt), "columns = [\n 'int 0',\n 'float 0.0',\n 'False',\n 'None',\n 'empty',\n]\n\n" "[[rows]]\n'int 0' = 0\n'float 0.0' = 0.0\nFalse = false\n\n", )
def test_nested_group_pack(self): """Tests if columns in multilevel groups are properly packed.""" COLUMN_GROUPS.extend( initialize_column_groups( [ "--ArrayOfTables", [ { "min": "RedMin", "max": "RedMax" }, { "min": "BlueMin", "max": "BlueMax" }, ], ], [ "--TableOfArrays", { "weight": ["Weight1", "Weight2", "Weight3"] } ], )) d2txt = D2TXT([ "RedMin", "BlueMin", "RedMax", "BlueMax", "Weight2", "Weight3", "Weight1", "Misc", ]) d2txt.extend([[10, 20, "unknown", 100, 0, 500, 1000, 4]]) self.assertEqual( d2txt_to_toml(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", )
def test_bitfield_decode(self): """Tests if bitfields are correctly decoded when saved to TOML file.""" d2txt = D2TXT(["aurafilter"]) d2txt.extend([["33025"], ["0"], ["65535"], ["4294901760"]]) self.maxDiff = None # pylint: disable=invalid-name self.assertEqual( d2txt_to_toml(d2txt), "columns = [\n 'aurafilter',\n]\n\n" "[[rows]]\naurafilter = [['FindPlayers', 'NotInsideTowns', 'IgnoreAllies']]\n\n" "[[rows]]\naurafilter = [[]]\n\n" "[[rows]]\naurafilter = " "[['FindPlayers', 'FindMonsters', 'FindOnlyUndead', 'FindMissiles', " "'FindObjects', 'FindItems', 'FindAttackable', 'NotInsideTowns', " "'UseLineOfSight', 'FindSelectable', 'FindCorpses', 'NotInsideTowns2', " "'IgnoreBoss', 'IgnoreAllies'], [0x840]]\n\n" "[[rows]]\naurafilter = " "[['IgnoreNPC', 'IgnorePrimeEvil', 'IgnoreJustHitUnits'], [0xFFF20000]]\n\n", )
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", )