コード例 #1
0
ファイル: JSDataGeneratorTest.py プロジェクト: rodu/av4vnstat
class JSDataGeneratorTest(unittest.TestCase):
    '''
    Created on 22 Apr 2012
    
    @author: Rodu
    '''
    def setUp(self):
        self.vnStatHandler = VnStatHandler()
        # Here we need to open a file for testing!
        vnStatDumpFile = open("../dummy_vnstat_test_dump.txt", 'r')
        self.vnStatHandler.setVnStatDumpFile(vnStatDumpFile)
        
        # The object under test
        self.dataParser = DataParser()
        self.dataParser.setVnStatHandler(self.vnStatHandler)



    def tearDown(self):
        pass


    def testGenerateMonthlyData(self):
        jsDatasetGenerator = JSDatasetGenerator()
        jsDatasetGenerator.setDataParser(self.dataParser)
        
        #    [ [ DateUTC(YYY, MM, DD), [Rx %] , [Tx %] ], 
        #      [ DateUTC(YYY, MM, DD), [Rx %] , [Tx %] ], ...]
        #
        #    To create the desired shape this are the proportions:
        #
        #        [0, 50, 30, 100, 30, 50, 0 ]
        #
        # Assuming the dummy data file to contain the following:
        #
        # m;1;1334980780;1024;2048;0;0;1
        # m;2;1334982490;8192;4096;0;0;1
        #
        expectedDataSet = ([['Date.UTC(2012,3,21,4,59,40)', 'Date.UTC(2012,3,21,5,28,10)'],
                            [1024.0, 8192.0], [2048.0, 4096.0],
                            [[0.0, 6.25, 3.75, 12.5, 3.75, 6.25, 0.0],
                             [0.0, 50.0, 30.0, 100.0, 30.0, 50.0, 0.0]],
                            [[0.0, 12.5, 7.5, 25.0, 7.5, 12.5, 0.0],
                             [0.0, 25.0, 15.0, 50.0, 15.0, 25.0, 0.0]]])
        
        jsDatasetGenerator.setJSFilePath("/dev/null")
        calculatedDataSet = jsDatasetGenerator.generateMonthlyDataSet()
        
        expectedDataSet = str(expectedDataSet).replace("'", "").replace("\"", "")
        calculatedDataSet = str(calculatedDataSet).replace("'", "").replace("\"", "")
        #print(expectedDataSet)
        #print(calculatedDataSet)
        
        self.assertEqual(expectedDataSet, calculatedDataSet,
                         "Calculated data do not match expected data set!")
コード例 #2
0
ファイル: Av4vnstat.py プロジェクト: rodu/av4vnstat
 def main(self):
     dataParser = DataParser()
     dataParser.setVnStatHandler(VnStatHandler())
     
     jsDataGenerator = JSDatasetGenerator()
     jsDataGenerator.setDataParser(dataParser)
     
     jsDataGenerator.generateUpdateTimeRecord()
     jsDataGenerator.generateHourlyDataSet()
     jsDataGenerator.generateDailyDataSet()
     jsDataGenerator.generateMonthlyDataSet()
     jsDataGenerator.generateTopTenDaysDataSet()
     
     jsDataGenerator.cleanup()
コード例 #3
0
ファイル: DataParserTest.py プロジェクト: rodu/av4vnstat
class DataParserTest(unittest.TestCase):
    '''
    Created on 21 Apr 2012
    
    @author: Rodu
    '''
    
    def setUp(self):
        self.vnStatHandler = VnStatHandler()
        # Here we need to open a file for testing!
        vnStatDumpFile = open("../dummy_vnstat_test_dump.txt", 'r')
        self.vnStatHandler.setVnStatDumpFile(vnStatDumpFile)
        
        # The object under test
        self.dataParser = DataParser()
        self.dataParser.setVnStatHandler(self.vnStatHandler)

    def tearDown(self):
        pass


    def testParseHourlyData(self):
        parsedHourlyData = self.dataParser.parseHourlyData()
        expectedHourlyData = [[1334980780L, 1.0, 2.0],
                              [1334982490L, 2.0, 1.0]]
        #print(parsedHourlyData)
        #print(expectedHourlyData)
        self.assertEqual(parsedHourlyData, expectedHourlyData,
                         "The returned data differs from the expected ones!")
    
    def testParseDailyData(self):
        parsedHourlyData = self.dataParser.parseDailyData()
        expectedHourlyData = [[1334703620L, 2.0, 2.0],
                              [1334796662L, 1.0, 1.0],
                              [1334876424L, 7.0, 7.0],
                              [1334977960L, 11.0, 11.0]]
        #print(parsedHourlyData)
        #print(expectedHourlyData)
        self.assertEqual(parsedHourlyData, expectedHourlyData,
                         "The returned data differs from the expected ones!")