コード例 #1
0
ファイル: tests_plugin_txt.py プロジェクト: turicas/rows
    def test_import_from_txt_retrieve_desired_data(self, mocked_create_table):
        mocked_create_table.return_value = 42

        # import using filename
        rows.import_from_txt(self.filename)
        call_args = mocked_create_table.call_args_list[0]
        self.assert_create_table_data(call_args)

        # import using fobj
        with open(self.filename, mode="rb") as fobj:
            rows.import_from_txt(fobj)
            call_args = mocked_create_table.call_args_list[1]
            self.assert_create_table_data(call_args)
コード例 #2
0
    def test_import_from_txt_retrieve_desired_data(self, mocked_create_table):
        mocked_create_table.return_value = 42

        # import using filename
        rows.import_from_txt(self.filename)
        call_args = mocked_create_table.call_args_list[0]
        self.assert_create_table_data(call_args)

        # import using fobj
        with open(self.filename, mode='rb') as fobj:
            rows.import_from_txt(fobj)
            call_args = mocked_create_table.call_args_list[1]
            self.assert_create_table_data(call_args)
コード例 #3
0
    def test_import_from_txt_uses_create_table(self, mocked_create_table):
        mocked_create_table.return_value = 42
        kwargs = {
            'some_key': 123,
            'other': 456,
        }
        result = rows.import_from_txt(self.filename,
                                      encoding=self.encoding,
                                      **kwargs)
        self.assertTrue(mocked_create_table.called)
        self.assertEqual(mocked_create_table.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_create_table.call_args
        called_data = call[1]
        meta = called_data.pop("meta")
        self.assertEqual(call[1], kwargs)

        expected_meta = {
            'imported_from': 'txt',
            'filename': self.filename,
            'encoding': self.encoding,
        }
        for key in expected_meta:
            self.assertEqual(expected_meta[key], meta[key])

        # test won't break if frame_style default changes in the future
        self.assertIn('frame_style', meta)
コード例 #4
0
ファイル: tests_plugin_txt.py プロジェクト: zanachka/rows
    def test_import_from_txt_uses_create_table(self, mocked_create_table):
        mocked_create_table.return_value = 42
        kwargs = {"some_key": 123, "other": 456}
        result = rows.import_from_txt(self.filename,
                                      encoding=self.encoding,
                                      **kwargs)
        self.assertTrue(mocked_create_table.called)
        self.assertEqual(mocked_create_table.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_create_table.call_args
        called_data = call[1]
        meta = called_data.pop("meta")
        self.assertEqual(call[1], kwargs)

        expected_meta = {
            "imported_from": "txt",
            "filename": self.filename,
            "encoding": self.encoding,
        }
        for key in expected_meta:
            self.assertEqual(expected_meta[key], meta[key])

        # test won't break if frame_style default changes in the future
        self.assertIn("frame_style", meta)
コード例 #5
0
    def _test_import_from_txt_works_with_custom_frame(self, frame_style):
        temp = tempfile.NamedTemporaryFile(delete=False)
        # self.files_to_delete.append(temp.name)
        print("*" * 100, temp.name)

        original_data = rows.import_from_txt(self.filename)
        rows.export_to_txt(utils.table,
                           temp.file,
                           encoding='utf-8',
                           frame_style=frame_style)

        new_data = rows.import_from_txt(temp.name)

        self.assertEqual(
            list(new_data),
            list(original_data),
            msg='failed to read information with frame_style == "{0}"'.format(
                frame_style))
コード例 #6
0
    def test_export_to_txt_fobj(self):
        # TODO: may test with codecs.open passing an encoding
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        rows.export_to_txt(utils.table, temp.file, encoding='utf-8')

        table = rows.import_from_txt(temp.name, encoding='utf-8')
        self.assert_table_equal(table, utils.table)
コード例 #7
0
ファイル: tests_plugin_txt.py プロジェクト: turicas/rows
    def _test_import_from_txt_works_with_custom_frame(self, frame_style):
        temp = tempfile.NamedTemporaryFile(delete=False)

        original_data = rows.import_from_txt(self.filename)
        rows.export_to_txt(
            utils.table, temp.file, encoding="utf-8", frame_style=frame_style
        )

        self._reset_txt_plugin()
        new_data = rows.import_from_txt(temp.name)

        self.assertEqual(
            list(new_data),
            list(original_data),
            msg='failed to read information with frame_style == "{0}"'.format(
                frame_style
            ),
        )
コード例 #8
0
ファイル: tests_plugin_txt.py プロジェクト: turicas/rows
    def test_export_to_txt_fobj(self):
        # TODO: may test with codecs.open passing an encoding
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        rows.export_to_txt(utils.table, temp.file, encoding="utf-8")

        table = rows.import_from_txt(temp.name, encoding="utf-8")
        self.assert_table_equal(table, utils.table)
コード例 #9
0
ファイル: tests_plugin_txt.py プロジェクト: turicas/rows
    def test_issue_168(self):
        temp = tempfile.NamedTemporaryFile(delete=False)
        filename = "{}.{}".format(temp.name, self.file_extension)
        self.files_to_delete.append(filename)

        table = rows.Table(fields=OrderedDict([("jsoncolumn", rows.fields.JSONField)]))
        table.append({"jsoncolumn": '{"python": 42}'})
        rows.export_to_txt(table, filename, encoding="utf-8")

        table2 = rows.import_from_txt(filename, encoding="utf-8")
        self.assert_table_equal(table, table2)
コード例 #10
0
ファイル: tests_plugin_txt.py プロジェクト: abelthf/rows
    def test_import_from_txt_uses_create_table(self, mocked_create_table):
        mocked_create_table.return_value = 42
        kwargs = {'encoding': self.encoding, 'some_key': 123, 'other': 456, }
        result = rows.import_from_txt(self.filename, **kwargs)
        self.assertTrue(mocked_create_table.called)
        self.assertEqual(mocked_create_table.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_create_table.call_args
        kwargs['meta'] = {'imported_from': 'txt', 'filename': self.filename, }
        self.assertEqual(call[1], kwargs)
コード例 #11
0
    def test_issue_168(self):
        temp = tempfile.NamedTemporaryFile(delete=False)
        filename = '{}.{}'.format(temp.name, self.file_extension)
        self.files_to_delete.append(filename)

        table = rows.Table(fields=OrderedDict([('jsoncolumn',
                                                rows.fields.JSONField)]))
        table.append({'jsoncolumn': '{"python": 42}'})
        rows.export_to_txt(table, filename, encoding='utf-8')

        table2 = rows.import_from_txt(filename, encoding='utf-8')
        self.assert_table_equal(table, table2)
コード例 #12
0
    def test_export_to_txt_filename(self):
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        rows.export_to_txt(utils.table, temp.name, encoding='utf-8')

        table = rows.import_from_txt(temp.name, encoding='utf-8')
        self.assert_table_equal(table, utils.table)

        with open(temp.name, mode='rb') as fobj:
            content = fobj.read()
        self.assertEqual(content[-10:].count(b'\n'), 1)
コード例 #13
0
ファイル: tests_plugin_txt.py プロジェクト: turicas/rows
    def test_export_to_txt_filename(self):
        # TODO: may test file contents
        temp = tempfile.NamedTemporaryFile(delete=False)
        self.files_to_delete.append(temp.name)
        rows.export_to_txt(utils.table, temp.name, encoding="utf-8")

        table = rows.import_from_txt(temp.name, encoding="utf-8")
        self.assert_table_equal(table, utils.table)

        with open(temp.name, mode="rb") as fobj:
            content = fobj.read()
        self.assertEqual(content[-10:].count(b"\n"), 1)
コード例 #14
0
ファイル: tests_plugin_txt.py プロジェクト: wnlima/rows
    def test_import_from_txt_uses_create_table(self, mocked_create_table):
        mocked_create_table.return_value = 42
        kwargs = {'some_key': 123, 'other': 456, }
        result = rows.import_from_txt(self.filename,
                                      encoding=self.encoding,
                                      **kwargs)
        self.assertTrue(mocked_create_table.called)
        self.assertEqual(mocked_create_table.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_create_table.call_args
        kwargs['meta'] = {'imported_from': 'txt',
                          'filename': self.filename,
                          'encoding': self.encoding,}
        self.assertEqual(call[1], kwargs)
コード例 #15
0
ファイル: tests_plugin_txt.py プロジェクト: turicas/rows
    def test_import_from_txt_uses_create_table(self, mocked_create_table):
        mocked_create_table.return_value = 42
        kwargs = {"some_key": 123, "other": 456}
        result = rows.import_from_txt(self.filename, encoding=self.encoding, **kwargs)
        self.assertTrue(mocked_create_table.called)
        self.assertEqual(mocked_create_table.call_count, 1)
        self.assertEqual(result, 42)

        call = mocked_create_table.call_args
        called_data = call[1]
        meta = called_data.pop("meta")
        self.assertEqual(call[1], kwargs)

        expected_meta = {
            "imported_from": "txt",
            "filename": self.filename,
            "encoding": self.encoding,
        }
        for key in expected_meta:
            self.assertEqual(expected_meta[key], meta[key])

        # test won't break if frame_style default changes in the future
        self.assertIn("frame_style", meta)