Skip to content

Commit

Permalink
Merge pull request #13 from freundTech/improv-test-base-classes
Browse files Browse the repository at this point in the history
Cleaned up test cases by creating base classes
  • Loading branch information
Podshot committed Oct 1, 2018
2 parents 4598e34 + b2ddc41 commit 7048cca
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 193 deletions.
106 changes: 47 additions & 59 deletions tests/test_format_proto_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,65 @@
from version_definitions import definition_manager


class TestPrototype112(unittest.TestCase):
class TestPrototypeBaseCases:
# Wrapped in another class, so it isn't executed on it's own.

class TestPrototype(unittest.TestCase):

def _setUp(self, version):
self.proto = definition_manager.DefinitionManager(version)

def test_get_internal_block(self):
stone_def = self.proto.get_internal_block(basename="stone")
granite_def = self.proto.get_internal_block(basename="granite")
oak_log_axis_x = self.proto.get_internal_block(
basename="oak_log", properties={"axis": "x"}
)

self.assertIsInstance(stone_def, dict)
self.assertEqual("Stone", stone_def["name"])


self.assertIsInstance(granite_def, dict)
self.assertEqual("Granite", granite_def["name"])
self.assertNotEqual(granite_def, stone_def)

self.assertIsInstance(oak_log_axis_x, dict)
self.assertEqual("Oak Log (East/West)", oak_log_axis_x["name"])
self.assertNotEqual(
oak_log_axis_x,
self.proto.get_internal_block(
basename="oak_log", properties={"axis": "y"}
),
)

with self.assertRaises(KeyError):
self.proto.get_internal_block(
resource_location="unknown", basename="stone"
)
self.proto.get_internal_block(
basename="stone", properties={"variant": "chiseled"}
)
self.proto.get_internal_block(basename="laterite")


class TestPrototype112(TestPrototypeBaseCases.TestPrototype):

def setUp(self):
self.proto = definition_manager.DefinitionManager("java_1_12")
self._setUp("java_1_12")

def test_direct_access(self):
self.assertEqual([1, 0], self.proto.blocks["minecraft:stone"])

def test_get_internal_block(self):
stone_def = self.proto.get_internal_block(basename="stone")
granite_def = self.proto.get_internal_block(basename="granite")
oak_log_axis_x = self.proto.get_internal_block(
basename="oak_log", properties={"axis": "x"}
)

self.assertIsInstance(stone_def, dict)
self.assertEqual("Stone", stone_def["name"])

self.assertIsInstance(granite_def, dict)
self.assertEqual("Granite", granite_def["name"])
self.assertNotEqual(granite_def, stone_def)

self.assertIsInstance(oak_log_axis_x, dict)
self.assertEqual("Oak Log (East/West)", oak_log_axis_x["name"])
self.assertNotEqual(
oak_log_axis_x,
self.proto.get_internal_block(basename="oak_log", properties={"axis": "y"}),
)

with self.assertRaises(KeyError):
self.proto.get_internal_block(resource_location="unknown", basename="stone")
self.proto.get_internal_block(
basename="stone", properties={"variant": "chiseled"}
)
self.proto.get_internal_block(basename="laterite")

class TestPrototype113(TestPrototypeBaseCases.TestPrototype):

class TestPrototype113(unittest.TestCase):
def setUp(self):
self.proto = definition_manager.DefinitionManager("java_1_13")
self._setUp("java_1_13")

def test_direct_access(self):
self.assertEqual("minecraft:stone", self.proto.blocks["minecraft:stone"])

def test_get_internal_block(self):
stone_def = self.proto.get_internal_block(basename="stone")
granite_def = self.proto.get_internal_block(basename="granite")
oak_log_axis_x = self.proto.get_internal_block(
basename="oak_log", properties={"axis": "x"}
)

self.assertIsInstance(stone_def, dict)
self.assertEqual("Stone", stone_def["name"])

self.assertIsInstance(granite_def, dict)
self.assertEqual("Granite", granite_def["name"])
self.assertNotEqual(stone_def, granite_def)

self.assertIsInstance(oak_log_axis_x, dict)
self.assertEqual("Oak Log (East/West)", oak_log_axis_x["name"])
self.assertNotEqual(
oak_log_axis_x,
self.proto.get_internal_block(basename="oak_log", properties={"axis": "y"}),
)

with self.assertRaises(KeyError):
self.proto.get_internal_block(resource_location="unknown", basename="stone")
self.proto.get_internal_block(
basename="stone", properties={"variant": "chiseled"}
)
self.proto.get_internal_block(basename="laterite")


if __name__ == "__main__":
unittest.main()
206 changes: 72 additions & 134 deletions tests/test_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,171 +14,109 @@
from test_utils import get_world_path


class AnvilWorldTestCase(unittest.TestCase):
def setUp(self):
self.world = world_loader.loader.load_world(get_world_path("1.12.2 World"))

def tearDown(self):
self.world.exit()

def test_get_block(self):
self.assertEqual("minecraft:air", self.world.get_block(0, 0, 0))
self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 3))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
self.assertEqual("minecraft:polished_granite", self.world.get_block(1, 70, 7))

with self.assertRaises(IndexError):
self.world.get_block(300, 300, 300)

def test_get_blocks(self):
self.assertIsInstance(
next(self.world.get_sub_chunks(slice(0, 10), slice(0, 10), slice(0, 10))),
SubChunk,
)
self.assertIsInstance(
next(self.world.get_sub_chunks(0, 0, 0, 10, 10, 10)), SubChunk
)
self.assertIsInstance(
next(self.world.get_sub_chunks(0, 0, 0, 10, 10, 10, 2, 2, 2)), SubChunk
)

with self.assertRaises(IndexError):
next(self.world.get_sub_chunks())

next(self.world.get_sub_chunks(slice(0, 10, 2)))
next(self.world.get_sub_chunks(slice(0, 10, 2), slice(0, 10, 2)))

next(self.world.get_sub_chunks(0))
next(self.world.get_sub_chunks(0, 0))
next(self.world.get_sub_chunks(0, 0, 0))

def test_clone_operation(self):

subbx1 = SubBox((1, 70, 3), (1, 70, 4))
src_box = SelectionBox((subbx1,))

subbx2 = SubBox((1, 70, 5), (1, 70, 6))
target_box = SelectionBox((subbx2,))

self.assertEqual(
"minecraft:stone", self.world.get_block(1, 70, 3)
) # Sanity check
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))

self.world.run_operation_from_operation_name("clone", src_box, target_box)

self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 5))

self.world.undo()

self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
class WorldTestBaseCases:
# Wrapped in another class, so it isn't executed on it's own.

self.world.redo()
class WorldTestCase(unittest.TestCase):

self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 5))
def _setUp(self, world_name):
self.world = world_loader.loader.load_world(get_world_path(world_name))

self.world.undo()
def tearDown(self):
self.world.exit()

self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))

def test_fill_operation(self):

subbox_1 = SubBox((1, 70, 3), (5, 71, 5))
box = SelectionBox((subbox_1,))

self.world.run_operation_from_operation_name("fill", box, "minecraft:stone")

for x, y, z in box:
self.assertEqual("minecraft:stone", self.world.get_block(x, y, z))

self.world.undo()
def test_get_block(self):
self.assertEqual("minecraft:air", self.world.get_block(0, 0, 0))
self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 3))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
self.assertEqual(
"minecraft:polished_granite", self.world.get_block(1, 70, 7)
)

self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 3))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
with self.assertRaises(IndexError):
self.world.get_block(300, 300, 300)

def test_get_blocks(self):
self.assertIsInstance(
next(
self.world.get_sub_chunks(slice(0, 10), slice(0, 10), slice(0, 10))
),
SubChunk,
)
self.assertIsInstance(
next(self.world.get_sub_chunks(0, 0, 0, 10, 10, 10)), SubChunk
)
self.assertIsInstance(
next(self.world.get_sub_chunks(0, 0, 0, 10, 10, 10, 2, 2, 2)), SubChunk
)

class Anvil2WorldTestCase(unittest.TestCase):
def setUp(self):
self.world = world_loader.loader.load_world(get_world_path("1.13 World"))
with self.assertRaises(IndexError):
next(self.world.get_sub_chunks())

def test_get_block(self):
self.assertEqual("minecraft:air", self.world.get_block(0, 0, 0))
self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 3))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
self.assertEqual("minecraft:polished_granite", self.world.get_block(1, 70, 7))
next(self.world.get_sub_chunks(slice(0, 10, 2)))
next(self.world.get_sub_chunks(slice(0, 10, 2), slice(0, 10, 2)))

with self.assertRaises(IndexError):
self.world.get_block(300, 300, 300)
next(self.world.get_sub_chunks(0))
next(self.world.get_sub_chunks(0, 0))
next(self.world.get_sub_chunks(0, 0, 0))

def test_get_blocks(self):
self.assertIsInstance(
next(self.world.get_sub_chunks(slice(0, 10), slice(0, 10), slice(0, 10))),
SubChunk,
)
self.assertIsInstance(
next(self.world.get_sub_chunks(0, 0, 0, 10, 10, 10)), SubChunk
)
self.assertIsInstance(
next(self.world.get_sub_chunks(0, 0, 0, 10, 10, 10, 2, 2, 2)), SubChunk
)
def test_clone_operation(self):
subbx1 = SubBox((1, 70, 3), (1, 70, 4))
src_box = SelectionBox((subbx1,))

with self.assertRaises(IndexError):
next(self.world.get_sub_chunks())
subbx2 = SubBox((1, 70, 5), (1, 70, 6))
target_box = SelectionBox((subbx2,))

next(self.world.get_sub_chunks(slice(0, 10, 2)))
next(self.world.get_sub_chunks(slice(0, 10, 2), slice(0, 10, 2)))
self.assertEqual(
"minecraft:stone", self.world.get_block(1, 70, 3)
) # Sanity check
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))

next(self.world.get_sub_chunks(0))
next(self.world.get_sub_chunks(0, 0))
next(self.world.get_sub_chunks(0, 0, 0))
self.world.run_operation_from_operation_name("clone", src_box, target_box)

def test_clone_operation(self):
self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 5))

subbx1 = SubBox((1, 70, 3), (1, 70, 4))
src_box = SelectionBox((subbx1,))
self.world.undo()

subbx2 = SubBox((1, 70, 5), (1, 70, 6))
target_box = SelectionBox((subbx2,))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))

self.assertEqual(
"minecraft:stone", self.world.get_block(1, 70, 3)
) # Sanity check
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
self.world.redo()

self.world.run_operation_from_operation_name("clone", src_box, target_box)
self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 5))

self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 5))
self.world.undo()

self.world.undo()
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))

self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
def test_fill_operation(self):
subbox_1 = SubBox((1, 70, 3), (5, 71, 5))
box = SelectionBox((subbox_1,))

self.world.redo()
self.world.run_operation_from_operation_name("fill", box, "minecraft:stone")

self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 5))
for x, y, z in box:
self.assertEqual(
"minecraft:stone",
self.world.get_block(x, y, z),
f"Failed at coordinate ({x},{y},{z})",
)

self.world.undo()
self.world.undo()

self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 3))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))

def test_fill_operation(self):

subbox_1 = SubBox((1, 70, 3), (5, 71, 5))
box = SelectionBox((subbox_1,))
class AnvilWorldTestCase(WorldTestBaseCases.WorldTestCase):

self.world.run_operation_from_operation_name("fill", box, "minecraft:stone")
def setUp(self):
self._setUp("1.12.2 World")

for x, y, z in box:
self.assertEqual(
"minecraft:stone",
self.world.get_block(x, y, z),
f"Failed at coordinate ({x},{y},{z})",
)

self.world.undo()
class Anvil2WorldTestCase(WorldTestBaseCases.WorldTestCase):

self.assertEqual("minecraft:stone", self.world.get_block(1, 70, 3))
self.assertEqual("minecraft:granite", self.world.get_block(1, 70, 5))
def setUp(self):
self._setUp("1.13 World")


if __name__ == "__main__":
Expand Down

0 comments on commit 7048cca

Please sign in to comment.