Пример #1
0
def convert(path, delimiter, encode, bom):
    """
    Convierte el csv que se pasa como parametro a lo que se seleccione.
    """
    csvfile = CSVFile(path)
    result = csvfile.export(encode=encode, delimiter=delimiter, with_bom=bom)
    click.echo(result)
Пример #2
0
 def test_longchar(self):
     """Test_longchar
     Si hay caracteres especiales mas adentrado
     el archivo no lo va a detectar.
     Se expandio la cantidad de lineas del buffer.
     """
     count = 0
     file_obj = CSVFile(longchar)
     for l in file_obj.inspect().open_csv():
         count += 1
     self.assertEqual(count, 1741)
Пример #3
0
class test_CSVFile(unittest.TestCase):

    SIMPLEF = "./files/simple.csv"

    def setUp(self):
        self.file_obj = CSVFile(self.SIMPLEF)

    @timed(0.1)
    def test_instanceCSV(self):
        self.assertIsInstance(self.file_obj, CSVFile)

    @timed(0.1)
    def test_opencsv(self):
        csv = self.file_obj.inspect().open_csv()
        self.assertIsInstance(csv, types.GeneratorType)

    @timed(0.1)
    def test_headers(self):
        header = ['id', 'names', 'lastnames', 'age']
        self.file_obj.inspect().set_generator().set_headers()
        self.assertEqual(self.file_obj.headers, header)

    @timed(0.2)
    def test_lenght(self):
        count = 0
        for l in self.file_obj.inspect().open_csv():
            count += 1
        self.assertEqual(count, 3)

    def test_longchar(self):
        """Test_longchar
        Si hay caracteres especiales mas adentrado
        el archivo no lo va a detectar.
        Se expandio la cantidad de lineas del buffer.
        """
        count = 0
        file_obj = CSVFile(longchar)
        for l in file_obj.inspect().open_csv():
            count += 1
        self.assertEqual(count, 1741)

    def test_chunks(self):
        result = []
        for c in self.file_obj.inspect().set_generator().make_chunks():
            result.append(c)

        self.assertEqual(len(result[0]), 3)
Пример #4
0
def show(path, lines):
    csvfile = CSVFile(path)
    result = csvfile\
        .inspect()\
        .set_generator(True)\
        .make_chunks(lines=lines).__next__()
    for r in result:
        click.echo(r)
Пример #5
0
class test_reader(unittest.TestCase):

    sfile = "./files/simple.csv"


    def setUp(self):
        self.csvfile = CSVFile(self.sfile)

    def tearDown(self):
        tmpfs = name_file(self.csvfile.path)
        if os.path.exists(tmpfs):
            os.remove(tmpfs)

    @timed(0.1)
    def test_CSVFile(self):

        self.assertIsInstance(self.csvfile, CSVFile)

    @timed(0.1)
    def test_read_file(self):
        count = 0
        for c in self.csvfile.inspect().set_headers().open_csv():
            count += 1

        self.assertEqual(count, 3)

    def test_chunks(self):
        count = 0
        for c in self.csvfile.inspect().set_generator(True).make_chunks():
            count += 1
        self.assertEqual(count, 1)

    def test_export_bom(self):
        result=self.csvfile.export(with_bom=True)

        self.assertTrue(os.path.isfile(result))

    def test_export_delimiter(self):
        result=self.csvfile.export(delimiter=",")
        with open(result, 'r') as f:
            line = f.readline()
            result = len(line.split(','))

        self.assertEqual(result, 4)
Пример #6
0
 def setUp(self):
     self.csvfile = CSVFile(self.sfile)
Пример #7
0
 def setUp(self):
     self.file_obj = CSVFile(self.SIMPLEF)