Пример #1
0
    def test_binary(self):
        for i in bin_samples:
            try:
                expect_filename = 'test_data/bin_expect/' + i
                data = open('test_data/bin_input/' + i).read()
                if len(data) != int(data[:5]):
                    data = data.decode('utf-8').encode('raw_unicode_escape')
                assert len(data) == int(data[:5])
                rec = MarcBinary(data)
                edition_marc_bin = read_edition(rec)
                assert edition_marc_bin
                #            if i.startswith('engin'):
                #                pprint(edition_marc_bin)
                #                assert False
                j = {}
                if os.path.exists(expect_filename):
                    j = simplejson.load(open(expect_filename))
                    if not j:
                        print expect_filename
                    assert j
                if not j:
                    simplejson.dump(edition_marc_bin,
                                    open(expect_filename, 'w'),
                                    indent=2)
                    continue
                self.assertEqual(sorted(edition_marc_bin.keys()),
                                 sorted(j.keys()))
                for k in edition_marc_bin.keys():
                    if isinstance(j[k], list):
                        for item1, item2 in zip(edition_marc_bin[k], j[k]):
                            #print (i, k, item1)
                            self.assertEqual(item1, item2)

                    self.assertEqual(edition_marc_bin[k], j[k])
                self.assertEqual(edition_marc_bin, j)
            except:
                print 'bad marc:', i
                raise

        i = 'talis_see_also.mrc'
        f = open('test_data/bin_input/' + i)
        rec = MarcBinary(f.read())
        self.assertRaises(SeeAlsoAsTitle, read_edition, rec)

        i = 'talis_no_title2.mrc'
        f = open('test_data/bin_input/' + i)
        rec = MarcBinary(f.read())
        self.assertRaises(NoTitle, read_edition, rec)
Пример #2
0
    def test_binary(self):
        for i in bin_samples:
            try:
                expect_filename = "%s/bin_expect/%s" % (test_data, i)
                data = open("%s/bin_input/%s" % (test_data, i)).read()
                if len(data) != int(data[:5]):
                    data = data.decode('utf-8').encode('raw_unicode_escape')
                assert len(data) == int(data[:5])
                rec = MarcBinary(data)
                edition_marc_bin = read_edition(rec)
                assert edition_marc_bin
                j = {}
                if os.path.exists(expect_filename):
                    j = simplejson.load(open(expect_filename))
                    assert j, "Unable to open test data: %s" % expect_filename
                else:
                    print "WARNING: test data %s not found, recreating it!" % expect_filename
                    simplejson.dump(edition_marc_bin,
                                    open(expect_filename, 'w'),
                                    indent=2)
                    continue
                self.assertEqual(sorted(edition_marc_bin.keys()),
                                 sorted(j.keys()))
                for k in edition_marc_bin.keys():
                    if isinstance(j[k], list):
                        for item1, item2 in zip(edition_marc_bin[k], j[k]):
                            self.assertEqual(item1, item2)

                    self.assertEqual(edition_marc_bin[k], j[k])
                self.assertEqual(edition_marc_bin, j)
            except:
                print 'Bad MARC:', i
                raise
Пример #3
0
    def test_subjects_bin(self, item, expected):
        filename = os.path.dirname(__file__) + '/test_data/bin_input/' + item

        data = open(filename).read()
        if len(data) != int(data[:5]):
            data = data.decode('utf-8').encode('raw_unicode_escape')
        rec = MarcBinary(data)
        assert read_subjects(rec) == expected
Пример #4
0
    def test_subjects_bin(self):
        for item, expect in bin_samples:
            filename = 'test_data/' + item

            data = open(filename).read()
            if len(data) != int(data[:5]):
                data = data.decode('utf-8').encode('raw_unicode_escape')
            rec = MarcBinary(data)
            yield self._test_subjects, rec, expect
Пример #5
0
next = 0
for data, length in read_file(f):
    pos = next
    next += length
    total += 1
    if show_field:
        get_first_tag(data, set([show_field]))
    if show_leader:
        print data[:24]
    if show_pos:
        print pos
    if verbose:
        show_book(data)
        print
    if build_rec:
        marc_rec = MarcBinary(data)
        edition_marc_bin = parse.read_edition(marc_rec)
        pprint(edition_marc_bin)
        print
    try:
        rec = read_edition(data)
    except SoundRecording:
        sound_rec += 1
        continue
    except BadDictionary:
        bad_dict += 1
        continue
    except NotBook:
        if show_non_books:
            show_book(data)
            print
Пример #6
0
 def test_raises_no_title(self):
     filename = "%s/bin_input/talis_no_title2.mrc" % test_data
     with open(filename, 'r') as f:
         rec = MarcBinary(f.read())
     self.assertRaises(NoTitle, read_edition, rec)
Пример #7
0
 def test_raises_see_also(self):
     filename = "%s/bin_input/talis_see_also.mrc" % test_data
     with open(filename, 'r') as f:
         rec = MarcBinary(f.read())
     self.assertRaises(SeeAlsoAsTitle, read_edition, rec)