示例#1
0
 def addFile(self):
     fileName = self.getCsvFileName()
     if fileName:
         parser = CSVParser()
         newTransactionMap = parser.parseCsv(fileName)
         self.transactionMap = parser.addTransactionMap(
             self.transactionMap, newTransactionMap)
         allMonths = list(self.transactionMap.keys())
         allMonths.sort()
         self.monthsList = allMonths
         self.loadMonth(self.currentMonth)
示例#2
0
 def loadNewFile(self):
     fileName = self.getCsvFileName()
     if fileName:
         parser = CSVParser()
         self.transactionMap = parser.parseCsv(fileName)
         allMonths = list(self.transactionMap.keys())
         allMonths.sort()
         self.monthsList = allMonths
         self.loadMonth(allMonths[-1])
         if len(allMonths) > 1:
             self.monthDecreaseButton.show()
         self.addMetricsButton()
示例#3
0
 def test_parser_kwargs(self):
     self.parser = CSVParser(fieldnames=["f1", "f2", "f3", "f4"], record_type="postgres", delimiter="-")
     data = "this-is-a-test"
     output = self.parser.execute(data)
     self.assertEqual(output["f1"], "this")
     self.assertEqual(output["f2"], "is")
     self.assertEqual(output["f3"], "a")
示例#4
0
 def test_execute_dict_with_parse_field(self):
     self.parser = CSVParser(fieldnames=["f1", "f2", "f3", "f4"], record_type="postgres", parse_field="myfield")
     data = {"myfield": "this,is,a,test"}
     output = self.parser.execute(data)
     self.assertEqual(output["f1"], "this")
     self.assertEqual(output["f2"], "is")
     self.assertEqual(output["f3"], "a")
示例#5
0
def run(csv_file_path):
    if not os.path.exists(csv_file_path) or os.path.isdir(csv_file_path):
        print 'Invalid file path given, please provide a valid csv file path'
        return

    parser = CSVParser(csv_file_path)
    try:
        raw_data = parser.parse()
    except ParseError as e:
        print 'Parse Error: ' + e
        return

    scoring_engine = ScoringEngine(raw_data)
    try:
        scoring_engine.process()
    except ScoringEngineError as e:
        print 'Exception occurred: ' + str(e)
        return
    except Exception as e:
        print 'Unknown Error: ' + str(e)
        return
示例#6
0
class CSVParserTestCase(TestCase):
    def setUp(self):
        self.parser = CSVParser(fieldnames=["f1", "f2", "f3", "f4"], record_type="postgres")

    def test_no_record_type(self):
        pass

    def test_execute_string(self):
        data = "this,is,a,test"
        output = self.parser.execute(data)
        self.assertEqual(output["type"], "postgres")
        self.assertEqual(output["f1"], "this")
        self.assertEqual(output["f2"], "is")
        self.assertEqual(output["f3"], "a")
        self.assertEqual(output["f4"], "test")

    def test_execute_dict(self):
        data = {"msg": "this,is,a,test"}
        output = self.parser.execute(data)
        self.assertEqual(output["f1"], "this")
        self.assertEqual(output["f2"], "is")
        self.assertEqual(output["f3"], "a")
        self.assertEqual(output["f4"], "test")

    def test_execute_dict_with_parse_field(self):
        self.parser = CSVParser(fieldnames=["f1", "f2", "f3", "f4"], record_type="postgres", parse_field="myfield")
        data = {"myfield": "this,is,a,test"}
        output = self.parser.execute(data)
        self.assertEqual(output["f1"], "this")
        self.assertEqual(output["f2"], "is")
        self.assertEqual(output["f3"], "a")

    def test_parser_kwargs(self):
        self.parser = CSVParser(fieldnames=["f1", "f2", "f3", "f4"], record_type="postgres", delimiter="-")
        data = "this-is-a-test"
        output = self.parser.execute(data)
        self.assertEqual(output["f1"], "this")
        self.assertEqual(output["f2"], "is")
        self.assertEqual(output["f3"], "a")
示例#7
0
 def setUp(self):
     self.parser = CSVParser(fieldnames=["f1", "f2", "f3", "f4"], record_type="postgres")
示例#8
0
 def test_parse(self):
     parser = CSVParser('sample_data.csv')
     rows = parser.parse()
     self.assertTrue(len(rows) > 0)