Ejemplo n.º 1
0
    def test_new_file(self):
        """Check that writing a completely new file is working
        """
        path = "output.mca"
        value = 1234567890

        # First, create file
        r_output = anvil.open(path)
        indexes = set()

        for index in range(0, anvil._NB_OF_ENTRIES, 3):
            r_output.save_chunk(index, value % (index + 2))
            indexes.add(index)

        self.assertEqual(indexes, set(r_output.indexes()))

        del r_output

        # Then, read it back and check its content
        r_input = anvil.open(path)

        self.assertEqual(indexes, set(r_input.indexes()))

        for index in r_input.indexes():
            chunk = r_input.load_chunk(index)
            self.assertEqual(value % (index + 2), chunk)

        os.unlink(path)
Ejemplo n.º 2
0
    def test_new_file(self):
        """Check that writing a completely new file is working
        """
        path = "output.mca"
        value = 1234567890

        # First, create file
        r_output = anvil.open(path)
        indexes = set()

        for index in range(0, anvil._NB_OF_ENTRIES, 3):
            r_output.save_chunk(index, value % (index + 2))
            indexes.add(index)

        self.assertEqual(indexes, set(r_output.indexes()))

        del r_output

        # Then, read it back and check its content
        r_input = anvil.open(path)

        self.assertEqual(indexes, set(r_input.indexes()))

        for index in r_input.indexes():
            chunk = r_input.load_chunk(index)
            self.assertEqual(value % (index + 2), chunk)

        os.unlink(path)
Ejemplo n.º 3
0
    def create_temporary_file(self, path):
        result = anvil.open(path)

        value = 1234567890

        for index in range(0, anvil._NB_OF_ENTRIES, 3):
            result.save_chunk(index, value % (index + 2))

        return result
Ejemplo n.º 4
0
    def create_temporary_file(self, path):
        result = anvil.open(path)

        value = 1234567890

        for index in range(0, anvil._NB_OF_ENTRIES, 3):
            result.save_chunk(index, value % (index + 2))

        return result
Ejemplo n.º 5
0
    def test_rewrite_file(self):
        """Check that reading and writing back an original NBT file is
        innocuous
        """
        r_input = self.create_temporary_file("anvil.mca")
        r_output = anvil.open(io.BytesIO())

        for index in r_input.indexes():
            chunk = r_input.load_chunk(index)
            r_output.save_chunk(index, chunk)

        self.assertEqual(set(r_input.indexes()), set(r_output.indexes()))

        for index in r_input.indexes():
            i_chunk = r_input.load_chunk(index)
            o_chunk = r_output.load_chunk(index)
            self.assertEqual(i_chunk, o_chunk)
Ejemplo n.º 6
0
    def test_rewrite_file(self):
        """Check that reading and writing back an original NBT file is
        innocuous
        """
        r_input = self.create_temporary_file("anvil.mca")
        r_output = anvil.open(io.BytesIO())

        for index in r_input.indexes():
            chunk = r_input.load_chunk(index)
            r_output.save_chunk(index, chunk)

        self.assertEqual(set(r_input.indexes()), set(r_output.indexes()))

        for index in r_input.indexes():
            i_chunk = r_input.load_chunk(index)
            o_chunk = r_output.load_chunk(index)
            self.assertEqual(i_chunk, o_chunk)
Ejemplo n.º 7
0
    def test_wipe_file(self):
        """Totally wiped files shall be removed
        """
        path = "output_wipe.mca"

        # First, create file
        self.create_temporary_file(path)
        os.stat(path)

        # Then, reload file
        r_output = anvil.open(path)

        for index in r_output.indexes():
            r_output.wipe_chunk(index)

        del r_output

        # File shall have disappeared
        with self.assertRaises(OSError):
            os.stat(path)
Ejemplo n.º 8
0
    def test_wipe_file(self):
        """Totally wiped files shall be removed
        """
        path = "output_wipe.mca"

        # First, create file
        self.create_temporary_file(path)
        os.stat(path)

        # Then, reload file
        r_output = anvil.open(path)

        for index in r_output.indexes():
            r_output.wipe_chunk(index)

        del r_output

        # File shall have disappeared
        with self.assertRaises(OSError):
            os.stat(path)