Beispiel #1
0
class LayerTestCase(unittest.TestCase):
    """
    Layer: Implements a layer of minecraft blocks.
    - Constructor should work with no arguments
    - getChunk() should return a valid chunk.
    - getChunk() should fail on bad inputs.
    
    Depends on chunk unit tests.
    """
    testobject = None  # this gets set in setUp, and tested in the subsequent tests. This allows subclassing of the tested object!

    def setUp(self):
        self.testobject = self.construct(Layer)

    def construct(self, thisclass):
        """
        self.construct: the solution to re-testing the superclasses' constructor. Usually we test the class's constructor in setUp,
        but this way we leave a nice hook to override setUp as needed, and to allow the subclass to call the constructor using 
        the superclass's test.
        
        Don't call the superclass's construct() method if you're changing the rules for constructing.
        """
        return thisclass()

    def test_getchunk(self):
        self.testobject = Layer()
        random.seed()
        chunk = self.testobject.getChunk(
            random.randint(-sys.maxint - 1, sys.maxint - 1),
            random.randint(-sys.maxint - 1, sys.maxint - 1))
        self.assertEquals(type(chunk), Chunk)
        validate_chunk_fields(chunk)

        try:
            self.testobject.getChunk(None, False)
        except Exception as e:
            pass
        else:
            self.fail("filter getChunk should fail on bad input ")
class LayerTestCase(unittest.TestCase):
    """
    Layer: Implements a layer of minecraft blocks.
    - Constructor should work with no arguments
    - getChunk() should return a valid chunk.
    - getChunk() should fail on bad inputs.
    
    Depends on chunk unit tests.
    """
    testobject = None # this gets set in setUp, and tested in the subsequent tests. This allows subclassing of the tested object!
    
    def setUp(self):
        self.testobject = self.construct(Layer)
        
    def construct(self, thisclass):
        """
        self.construct: the solution to re-testing the superclasses' constructor. Usually we test the class's constructor in setUp,
        but this way we leave a nice hook to override setUp as needed, and to allow the subclass to call the constructor using 
        the superclass's test.
        
        Don't call the superclass's construct() method if you're changing the rules for constructing.
        """
        return thisclass()
    
    def test_getchunk(self):
        self.testobject = Layer()
        random.seed()
        chunk = self.testobject.getChunk(random.randint(-sys.maxint-1, sys.maxint - 1),random.randint(-sys.maxint -1, sys.maxint - 1))
        self.assertEquals(type(chunk), Chunk)
        validate_chunk_fields(chunk)
        
        try:
            self.testobject.getChunk(None, False)
        except Exception as e:
            pass
        else:
            self.fail("filter getChunk should fail on bad input ")