def test_get_detailed_ender_chest(get_inv_m, analyse_m, player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) assert player.get_detailed_ender_chest() == analyse_m.return_value analyse_m.assert_called_once_with(get_inv_m.return_value) get_inv_m.assert_called_once_with()
def test_get_inventory(gnbtd_m, player_mocks): gnbtd_m.return_value = {"Inventory": "<inventory>"} gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) assert player.get_inventory() == "<inventory>"
def test_get_ender_chest(gnbtd_m, player_mocks): gnbtd_m.return_value = {"EnderItems": "<ender-items>"} gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) assert player.get_ender_chest() == "<ender-items>"
def test_position(gnbtd_m, player_mocks, unparsed_dim, parsed_dim): gnbtd_m.return_value = {"Pos": [321, 255, 123], "Dimension": unparsed_dim} gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) expected = Coords(parsed_dim, 321, 255, 123) assert player.get_position() == expected
def test_repr(player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" adv_file = AdvancementsFile("<path>") stats_file = StatsFile("<path>") data_file = PlayerDataFile("<path>") player = Player("<uuid>", adv_file, stats_file, data_file) assert repr(player) == "Player(<username>|<mode> - <uuid>)" assert gm_m.call_count == 1 assert gu_m.call_count == 1
def test_eq(player_mocks): gm_m, gu_m = player_mocks adv_file = AdvancementsFile("<path>") stats_file = StatsFile("<path>") data_file = PlayerDataFile("<path>") player1 = Player("<uuid>", adv_file, stats_file, data_file) player2 = Player("<uuid>", adv_file, stats_file, data_file) assert player1 == player2 assert gm_m.call_count == 2 assert gu_m.call_count == 2
def test_to_extended_repr(player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) expected = ("Player(<username>|<mode> - <uuid>, " "player_data_file='<data-path>', stats_file='<stats-path>', " "advancements_file='<adv-path>')") assert player.to_extended_repr() == expected
def test_neq(player_mocks): gm_m, gu_m = player_mocks adv_file1 = AdvancementsFile("<path-1>") stats_file1 = StatsFile("<path-1>") data_file1 = PlayerDataFile("<path-1>") adv_file2 = AdvancementsFile("<path-2>") stats_file2 = StatsFile("<path-2>") data_file2 = PlayerDataFile("<path-2>") player1 = Player("<uuid-1>", adv_file1, stats_file1, data_file1) player2 = Player("<uuid-2>", adv_file1, stats_file1, data_file1) player3 = Player("<uuid-1>", adv_file2, stats_file1, data_file1) player4 = Player("<uuid-1>", adv_file1, stats_file2, data_file1) player5 = Player("<uuid-1>", adv_file1, stats_file1, data_file2) assert player1 != player2 assert player1 != player3 assert player1 != player4 assert player1 != player5 assert gm_m.call_count == 5 assert gu_m.call_count == 5
def test_ok(self, player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<username>" gu_m.return_value = "<mode>" adv_file = AdvancementsFile("<path>") stats_file = StatsFile("<path>") data_file = PlayerDataFile("<path>") permutations = list( itertools.permutations((adv_file, stats_file, data_file))) players = [] for files in permutations: players.append(Player("<uuid>", *files)) assert gm_m.call_count == gu_m.call_count == 6 for player in players[1:]: assert player == players[0]
def test_error(self, player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<username>" gu_m.return_value = "<mode>" adv_file = AdvancementsFile("<path>") stats_file = StatsFile("<path>") data_file = PlayerDataFile("<path>") permutations = list( itertools.permutations((adv_file, stats_file, data_file), 2)) for files in permutations: with pytest.raises(InvalidPlayerError, match="Can't create Player"): Player("<uuid>", *files) assert gm_m.call_count == gu_m.call_count == 6 with pytest.raises(TypeError, match="files can't be"): Player("<uuid>", "invalid-file")
def test_get_nbt_data(player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" pdf_m = mock.MagicMock() nbt_path = Path(__file__).parent.parent.joinpath( "test_data/nbt-example.dat") pdf_m.read_bytes.return_value = nbt_path.read_bytes() sf_m = mock.MagicMock() af_m = mock.MagicMock() adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) player.player_data_file = pdf_m player.stats_file = sf_m player.advancements_file = af_m nbt_data = player.get_nbt_data() assert len(nbt_data) == 52 assert nbt_data["AbsorptionAmount"] == 0 assert nbt_data["DataVersion"] == 2567 assert nbt_data["DeathTime"] == 0 assert nbt_data["Dimension"] == "minecraft:overworld" assert len(nbt_data["EnderItems"]) == 15 assert nbt_data["Fire"] == 0 assert nbt_data["HurtByTimestamp"] == 2183960 assert len(nbt_data["Inventory"]) == 10 assert nbt_data["Motion"][0] == 0 assert nbt_data["Motion"][1] == 0 assert nbt_data["Motion"][2] == 0 assert nbt_data["OnGround"] == 0 assert nbt_data["PortalCooldown"] == 0 assert nbt_data["foodLevel"] == 17 assert nbt_data["seenCredits"] == 1 pdf_m.read_bytes.assert_called_once_with()
def test_analyse_items(player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" pdf_m = mock.MagicMock() nbt_path = Path(__file__).parent.parent.joinpath( "test_data/nbt-example.dat") pdf_m.read_bytes.return_value = nbt_path.read_bytes() sf_m = mock.MagicMock() af_m = mock.MagicMock() adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) player.player_data_file = pdf_m player.stats_file = sf_m player.advancements_file = af_m nbt_data = player.get_nbt_data() items = player.analyse_items(nbt_data["Inventory"]) expected_items = { "andesite": 6, "cobblestone": 16, "diorite": 36, "flint and steel": 1, "gravel": 3, "orange terracotta": 8, "red terracotta": 9, "stone": 1, "tnt": 1, "torch": 1, } expected_items = [Item(k, v) for k, v in expected_items.items()] expected_items.sort(key=lambda x: x.name) assert items == expected_items
def test_remove(player_mocks): gm_m, gu_m = player_mocks gm_m.return_value = "<mode>" gu_m.return_value = "<username>" pdf_m = mock.MagicMock() sf_m = mock.MagicMock() af_m = mock.MagicMock() adv_file = AdvancementsFile("<adv-path>") stats_file = StatsFile("<stats-path>") data_file = PlayerDataFile("<data-path>") player = Player("<uuid>", adv_file, stats_file, data_file) player.player_data_file = pdf_m player.stats_file = sf_m player.advancements_file = af_m player.remove() pdf_m.remove.assert_called_once_with() sf_m.remove.assert_called_once_with() af_m.remove.assert_called_once_with()
def test_inheritance(self): advancements_file = AdvancementsFile("path") assert isinstance(advancements_file, AdvancementsFile) assert isinstance(advancements_file, File)