def test_example1(self): example1 = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', 'example1.csv' ) argv = [] argv.append("-f") argv.append(example1) argv.append("--fieldnames") argv.append("date,text,value,currency,") argv.append("--timestamp-field") argv.append("date") argv.append("--timestamp-format") argv.append("%d.%m.%Y") argv.append("--output-format") argv.append("{text}") argv.append("--properties") argv.append("currency,value") memacs = Csv(argv=argv) data = memacs.test_get_entries() self.assertEqual(data[0], "** <2012-02-23 Thu> Amazon") self.assertEqual(data[1], " :PROPERTIES:") self.assertEqual(data[2], " :CURRENCY: EUR") self.assertEqual(data[3], " :VALUE: 100,00") self.assertEqual(data[4], " :ID: a9cfa86bd9d89b72f35bfca0bb75131be0ca86b1") self.assertEqual(data[5], " :END:")
def test_example1(self): example1 = os.path.dirname(os.path.abspath(__file__)) + \ os.sep + "tmp" + os.sep + "example1.csv" argv = [] argv.append("-f") argv.append(example1) argv.append("-ti") argv.append("5") argv.append("-tf") argv.append("%d.%m.%Y %H:%M:%S:%f") argv.append("-oi") argv.append("4 3 1") memacs = Csv(argv=argv) # or when in append mode: # memacs = Foo(argv=argv.split(), append=True) data = memacs.test_get_entries() # generate assertEquals :) # for d in range(len(data)): # print "self.assertEqual(\n\tdata[%d],\n\t\"%s\")" % \ # (d, data[d]) self.assertEqual( data[0], "** <2012-02-23 Thu 14:40:59> EUR 100,00 Amazon") self.assertEqual( data[1], " :PROPERTIES:") self.assertEqual( data[2], " :ID: 5526fcec678ca1dea255b60177e5daaa737d3805") self.assertEqual( data[3], " :END:")
def test_example2_delimiter(self): example1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'example2.csv') argv = [] argv.append("--delimiter") argv.append("|") argv.append("-f") argv.append(example1) argv.append("-ti") argv.append("5") argv.append("-tf") argv.append("%d.%m.%Y %H:%M:%S:%f") argv.append("-oi") argv.append("4 3 1") memacs = Csv(argv=argv) data = memacs.test_get_entries() self.assertEqual(data[0], "** <2012-02-23 Thu 14:40> EUR 100,00 Amazon") self.assertEqual(data[1], " :PROPERTIES:") self.assertEqual( data[2], " :ID: 5526fcec678ca1dea255b60177e5daaa737d3805") self.assertEqual(data[3], " :END:")
def test_example2_delimiter(self): example1 = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', 'example2.csv' ) argv = [] argv.append("--delimiter") argv.append("|") argv.append("-f") argv.append(example1) argv.append("-ti") argv.append("5") argv.append("-tf") argv.append("%d.%m.%Y %H:%M:%S:%f") argv.append("-oi") argv.append("4 3 1") memacs = Csv(argv=argv) data = memacs.test_get_entries() self.assertEqual( data[0], "** <2012-02-23 Thu 14:40> EUR 100,00 Amazon") self.assertEqual( data[1], " :PROPERTIES:") self.assertEqual( data[2], " :ID: 5526fcec678ca1dea255b60177e5daaa737d3805") self.assertEqual( data[3], " :END:")
def main(): global memacs memacs = Csv(prog_version=PROG_VERSION_NUMBER, prog_version_date=PROG_VERSION_DATE, prog_description=PROG_DESCRIPTION, prog_short_description=PROG_SHORT_DESCRIPTION, prog_tag=PROG_TAG, copyright_year=COPYRIGHT_YEAR, copyright_authors=COPYRIGHT_AUTHORS # use_config_parser_name=CONFIG_PARSER_NAME ) memacs.handle_main()
def test_example2(self): example1 = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', 'example2.csv' ) argv = [] argv.append("--delimiter") argv.append("|") argv.append("-f") argv.append(example1) argv.append("--timestamp-field") argv.append("date") argv.append("--output-format") argv.append("{text}") memacs = Csv(argv=argv) data = memacs.test_get_entries() self.assertEqual(data[0], "** <2012-02-23 Thu 14:40> Alibaba") self.assertEqual(data[1], " :PROPERTIES:") self.assertEqual(data[2], " :ID: b1a598a360d4766cf94822cdcd96629f0b3936ef") self.assertEqual(data[3], " :END:")
def test_example2(self): example1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'example2.csv') argv = [] argv.append("--delimiter") argv.append("|") argv.append("-f") argv.append(example1) argv.append("--timestamp-field") argv.append("date") argv.append("--output-format") argv.append("{text}") memacs = Csv(argv=argv) data = memacs.test_get_entries() self.assertEqual(data[0], "** <2012-02-23 Thu 14:40> Alibaba") self.assertEqual(data[1], " :PROPERTIES:") self.assertEqual( data[2], " :ID: 08cfc2bf06e9f2a235641912ea7c7d7c87072ad3") self.assertEqual(data[3], " :END:")
# Time-stamp: <2012-02-22 17:12:59 armin> from memacs.csv import Csv PROG_VERSION_NUMBER = u"0.1" PROG_VERSION_DATE = u"2012-02-24" PROG_SHORT_DESCRIPTION = u"Memacs for csv files" PROG_TAG = u"csv" PROG_DESCRIPTION = u""" This Memacs module will parse csv files """ # set CONFIG_PARSER_NAME only, when you want to have a config file # otherwise you can comment it out # CONFIG_PARSER_NAME="memacs-example" COPYRIGHT_YEAR = "2012" COPYRIGHT_AUTHORS = """Karl Voit <*****@*****.**>, Armin Wieser <*****@*****.**>""" if __name__ == "__main__": memacs = Csv( prog_version=PROG_VERSION_NUMBER, prog_version_date=PROG_VERSION_DATE, prog_description=PROG_DESCRIPTION, prog_short_description=PROG_SHORT_DESCRIPTION, prog_tag=PROG_TAG, copyright_year=COPYRIGHT_YEAR, copyright_authors=COPYRIGHT_AUTHORS) memacs.handle_main()