How to use the pymarc.TextWriter function in pymarc

To help you get started, we’ve selected a few pymarc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edsu / pymarc / test / test_writer.py View on Github external
def test_writing_0_records(self):
        file_handle = StringIO()
        try:
            writer = pymarc.TextWriter(file_handle)
            writer.close(close_fh=False)
            self.assertEqual(
                file_handle.getvalue(),
                "",
                "Nothing should be have been written to the file handle",
            )
        finally:
            file_handle.close()
github edsu / pymarc / test / test_writer.py View on Github external
def test_close_false(self):
        """If close_fh is false, then the file handle is NOT closed."""
        file_handle = StringIO()
        self.assertFalse(file_handle.closed, "The file handle should be open")
        writer = pymarc.TextWriter(file_handle)
        self.assertFalse(file_handle.closed, "The file handle should still be open")
        writer.close(close_fh=False)
        self.assertFalse(
            file_handle.closed,
            "The file handle should NOT close when the writer closes",
        )
github edsu / pymarc / test / test_writer.py View on Github external
=LDR            22        4500
            =008  090227s2009\\\\mau\\\\\\\\\\\\\\\\\chi\d
            =100  00$ame
            =245  00$aFoo /$cby me.

            =LDR            22        4500
            =100  00$ame
            =245  00$aFoo /$cby me.

            =LDR            22        4500
            =245  00$aFoo /$cby me.
        """
        expected = textwrap.dedent(expected[1:])
        file_handle = StringIO()
        try:
            writer = pymarc.TextWriter(file_handle)
            record = pymarc.Record()
            record.add_field(
                pymarc.Field("008", data="090227s2009    mau                 chi d")
            )
            record.add_field(pymarc.Field("100", ["0", "0"], ["a", "me"]))
            record.add_field(
                pymarc.Field("245", ["0", "0"], ["a", "Foo /", "c", "by me."])
            )
            writer.write(record)
            record = pymarc.Record()
            record.add_field(pymarc.Field("100", ["0", "0"], ["a", "me"]))
            record.add_field(
                pymarc.Field("245", ["0", "0"], ["a", "Foo /", "c", "by me."])
            )
            writer.write(record)
            record = pymarc.Record()
github edsu / pymarc / test / test_writer.py View on Github external
def test_writing_empty_record(self):
        expected = r"""
            =LDR            22        4500
        """
        expected = textwrap.dedent(expected[1:])
        file_handle = StringIO()
        try:
            writer = pymarc.TextWriter(file_handle)
            record = pymarc.Record()
            writer.write(record)
            writer.close(close_fh=False)
            self.assertEquals(file_handle.getvalue(), expected)
        finally:
            file_handle.close()
github edsu / pymarc / test / test_writer.py View on Github external
def test_close_true(self):
        """If close_fh is true, then the file handle is also closed."""
        file_handle = StringIO()
        self.assertFalse(file_handle.closed, "The file handle should be open")
        writer = pymarc.TextWriter(file_handle)
        self.assertFalse(file_handle.closed, "The file handle should still be open")
        writer.close()
        self.assertTrue(
            file_handle.closed, "The file handle should close when the writer closes"
        )
github edsu / pymarc / test / test_writer.py View on Github external
def test_writing_1_record(self):
        expected = r"""
            =LDR            22        4500
            =100  00$ame
            =245  00$aFoo /$cby me.
        """
        expected = textwrap.dedent(expected[1:])
        file_handle = StringIO()
        try:
            writer = pymarc.TextWriter(file_handle)
            record = pymarc.Record()
            record.add_field(pymarc.Field("100", ["0", "0"], ["a", "me"]))
            record.add_field(
                pymarc.Field("245", ["0", "0"], ["a", "Foo /", "c", "by me."])
            )
            writer.write(record)
            writer.close(close_fh=False)
            self.assertEquals(file_handle.getvalue(), expected)
        finally:
            file_handle.close()