From 0d818eced5cfc262cf63d939bdd55b1acef3f290 Mon Sep 17 00:00:00 2001 From: Austin Marino Date: Mon, 14 Oct 2019 17:02:39 -0700 Subject: [PATCH] Ran test to ensure it works --- beetsplug/export.py | 6 ++-- test/test_export.py | 69 +++++++++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/beetsplug/export.py b/beetsplug/export.py index 2f6af072e..f0384ce55 100644 --- a/beetsplug/export.py +++ b/beetsplug/export.py @@ -67,13 +67,11 @@ class ExportPlugin(BeetsPlugin): # XML module formatting options. 'formatting': { # The output encoding. - 'encoding': 'unicode', + 'encoding': 'utf-8', # Controls if XML declaration should be added to the file. 'xml_declaration': True, # Can be either "xml", "html" or "text" (default is "xml"). - 'method': 'xml', - # Controls formatting of elements that contain no content. - 'short_empty_elements': True + 'method': 'xml' } } # TODO: Use something like the edit plugin diff --git a/test/test_export.py b/test/test_export.py index 0fae57ca4..35ad14718 100644 --- a/test/test_export.py +++ b/test/test_export.py @@ -20,6 +20,8 @@ from __future__ import division, absolute_import, print_function import unittest from test.helper import TestHelper +import re + class ExportPluginTest(unittest.TestCase, TestHelper): def setUp(self): @@ -31,36 +33,61 @@ class ExportPluginTest(unittest.TestCase, TestHelper): self.teardown_beets() def execute_command(self, format_type, artist): - options = ' -f %s -i "track,album" s'.format(format_type, artist) - actual = self.run_with_output('export', options) - return actual.replace(" ", "") - - def create_item(self, album='talbum', artist='tartist', track='ttrack'): - item1, = self.add_item_fixtures() - item1.album = album - item1.artist = artist - item1.track = track - item1.write() - item1.store() - return item1 + actual = self.run_with_output( + 'export', + '-f', format_type, + '-i', 'album,title', + artist + ) + return re.sub("\\s+", '', actual) + + def create_item(self): + item, = self.add_item_fixtures() + item.artist = 'xartist' + item.title = 'xtitle' + item.album = 'xalbum' + item.write() + item.store() + return item def test_json_output(self): item1 = self.create_item() - actual = self.execute_command(format_type='json',artist=item1.artist) - expected = '[{"track":%s,"album":%s}]'.format(item1.track,item1.album) - self.assertIn(first=expected,second=actual,msg="export in JSON format failed") + actual = self.execute_command( + format_type='json', + artist=item1.artist + ) + expected = u'[{"album":"%s","title":"%s"}]'\ + % (item1.album, item1.title) + self.assertIn( + expected, + actual + ) def test_csv_output(self): item1 = self.create_item() - actual = self.execute_command(format_type='json',artist=item1.artist) - expected = 'track,album\n%s,%s'.format(item1.track,item1.album) - self.assertIn(first=expected,second=actual,msg="export in CSV format failed") + actual = self.execute_command( + format_type='csv', + artist=item1.artist + ) + expected = u'album,title%s,%s'\ + % (item1.album, item1.title) + self.assertIn( + expected, + actual + ) def test_xml_output(self): item1 = self.create_item() - actual = self.execute_command(format_type='json',artist=item1.artist) - expected = '%s%s'.format(item1.track,item1.album) - self.assertIn(first=expected,second=actual,msg="export in XML format failed") + actual = self.execute_command( + format_type='xml', + artist=item1.artist + ) + expected = u'%s%s'\ + % (item1.album, item1.title) + self.assertIn( + expected, + actual + ) def suite():