def test_getID (self): ''' Test that digital co-ordinates are rationalised to the bottom left corner of a tile in the simplified system Test that the minus does not follow the dot in the ID (s3 does not tolerate this). ''' t = Tile (10,20) self.failUnless ( t.getID () == "10.20" ) t = Tile (-1,20) self.failUnless ( t.getID () == "m-1.20" )
def testGRBasicCache(self): ''' Test the basic cache in the Graph Repository ''' t1 = Tile ( 1, 1 ) t2 = Tile ( 2, 2 ) t3 = Tile ( 5, 5 ) t4 = Tile ( 6, 6 ) immutableList = [Tile(1,1).getID(), t2 ] GR = GraphRepository ( immutableList ) GR[t1] = self.graph_1_1 GR[t2] = self.graph_2_2 GR[t3] = self.graph_3_3 GR[t4] = self.graph_4_4 self.failUnless ( len (GR) == 4 ) # trim should do nothing unless maxSize has been set GR.trim (4) self.failUnless ( len (GR) == 4 ) # access t3, then t3 will be the most accessed # and preserved x = GR[t3] # but t4, should be the candidate that is discarded GR.trim (3) self.failUnless ( len (GR) == 3 ) self.failUnless ( t4.getID () not in GR ) self.failUnless ( t3.getID () in GR ) GR.trim (2) self.failUnless ( len (GR) == 2 ) self.failUnless ( t3.getID () not in GR ) # this should not work because there are some # immutable tiles GR.trim (1) self.failUnless ( len (GR) == 2 )
def testGRAccessing(self): ''' Test setting and accessing Tiles from the Repo ''' t1 = Tile ( 1, 0 ) t2 = Tile ( 1, 1 ) GR = GraphRepository ([]) GR[t1] = self.graph_1_1 GR[t2] = self.graph_2_2 self.failUnless ( GR[t1.getID()]['a'] == 1 ) self.failUnless ( GR[t2.getID()]['c'] == 3 ) # better not to do this self.failUnless ( GR[t1]['a'] == 1 ) self.failUnless ( GR[t2]['c'] == 3 ) # safer way self.failUnless ( GR.accessFrequency[ t1.getID () ] == 2 ) self.failUnless ( t1.getID () in GR ) notThereTile = Tile (1,100) try: print (GR [notThereTile] ) except AppError as ae: self.failUnless ( ae.args[1] == 'GraphRepository' ) # try deleting poppedVal = GR.pop (t1.getID() ) self.failUnless ( len (GR)== 1 ) self.failUnless ( poppedVal == self.graph_1_1 )
def testCreate(self): ''' Create a Graph repository using the DataStore ''' t1 = Tile (1 ,1) t2 = Tile (2 ,2) tileList = [t1, t2] GRF = GraphRepositoryFactory ( ) graphRepo= GRF.create (self.TestDataStore , tileList ) self.failUnless ( len (graphRepo) == 2 ) self.failUnless ( t1.getID () in graphRepo ) self.failUnless ( t2.getID () in graphRepo )
def _getStringList (self, thisTile): ''' Search for lines in the file that are in Tile thisTile return a list of those matched lines. ''' lstLines = [] try: fs = open ( self.filePath, 'r' ) if (self.hasHeader): fs.readline () allLines = fs.readlines () for thisLine in allLines: # print thisLine cols = thisLine.split ("|") centroidWKT= cols [8] # centroidWKT is like "POINT (0.2343 0.2332432)" tmpList = centroidWKT.replace ('POINT(','' ).replace ( ')','' ).split (" ") X = float (tmpList[0] ) Y = float (tmpList[1] ) # Find the integer "floor" value of x & y co-ordinates xVal = int (math.floor ( X ) ) yVal = int (math.floor ( Y ) ) if ( Tile ( xVal , yVal ) == thisTile ): lstLines.append ( thisLine ) fs.close () except IOError as e: import traceback, utils utils.logError ( traceback.format_exc() ) raise AppError (utils.timestampStr (), 'FileDataStore', 'open/read file', e ) return lstLines