def test_render_document_list_no_valid_fields(self): # if there are no fields to print, don't print anything. This comes from # a bug (BZ 847091) where blank lines were printed for each document, # even if no fields from that document were printed. r = Recorder() p = core.PulpPrompt(output=r, record_tags=True) docs = [ { 'id': 'd1', 'name': 'document 1', 'description': 'description 1' }, { 'id': 'd2', 'name': 'document 2', 'description': 'description 2' }, { 'id': 'd3', 'name': 'document 3', 'description': 'description 3' }, ] f = ['notavalidfield'] p.render_document_list(docs, order=['name'], filters=f) # only print the ANSI reset and new line character, but not any documents self.assertEqual(len(r.lines), 2)
def test_render_document_list_with_full_order(self): # Test r = Recorder() p = core.PulpPrompt(output=r, record_tags=True) docs = [ { 'id': 'd1', 'name': 'document 1' }, { 'id': 'd2', 'name': 'document 2' }, { 'id': 'd3', 'name': 'document 3' }, ] p.render_document_list(docs, order=['name', 'id']) # Verify self.assertEqual(len(docs) * len(docs[0]), len(p.get_write_tags())) self.assertEqual( 0, len([t for t in p.get_write_tags() if t is not core.TAG_DOCUMENT])) self.assertTrue('Name' in r.lines[1]) self.assertTrue('Id' in r.lines[2]) self.assertEqual('\n', r.lines[3])
def test_render_document_list_with_filter(self): # Test r = Recorder() p = core.PulpPrompt(output=r, record_tags=True) docs = [ { 'id': 'd1', 'name': 'document 1' }, { 'id': 'd2', 'name': 'document 2' }, { 'id': 'd3', 'name': 'document 3' }, ] p.render_document_list(docs, filters=['name']) # Verify self.assertEqual(len(docs), len(p.get_write_tags())) self.assertEqual( 0, len([t for t in p.get_write_tags() if t is not core.TAG_DOCUMENT])) self.assertTrue('Name' in r.lines[1]) self.assertEqual('\n', r.lines[2]) self.assertTrue( 'Name' in r.lines[3]) # shouldn't be "Id" since that was filtered out
def test_render_spacer(self): # Test r = Recorder() p = core.PulpPrompt(output=r, enable_color=False) p.render_spacer(lines=4) # Verify self.assertEqual(4, len(r.lines)) self.assertEqual(0, len([l for l in r.lines if l != '\n']))
def test_render_document_list_omit_hidden_false(self): # Test r = Recorder() p = core.PulpPrompt(output=r, record_tags=True) docs = [{'_id': 'd1', 'name': 'document 1'}] p.render_document_list(docs, omit_hidden=False) # Verify self.assertEqual(2, len(p.get_write_tags())) self.assertEqual( 0, len([t for t in p.get_write_tags() if t is not core.TAG_DOCUMENT])) self.assertTrue('_id' in r.lines[1])
def test_write_color(self): """ Tests the color functionality built into write works. """ # Setup recorder = Recorder() prompt = Prompt(output=recorder) # Test prompt.write('Hulk', color=okaara.prompt.COLOR_RED, new_line=False) # Verify expected = okaara.prompt.COLOR_RED + 'Hulk' + okaara.prompt.COLOR_WHITE self.assertEqual(recorder.lines[1], expected)
def test_render_document_list_order_and_filter(self): # Test r = Recorder() p = core.PulpPrompt(output=r, record_tags=True) docs = [ {'id' : 'd1', 'name' : 'document 1', 'description' : 'description 1'}, ] f = ['id', 'name'] p.render_document_list(docs, order=['name'], filters=f) # Verify self.assertEqual(len(docs)* len(f), len(p.get_write_tags())) self.assertEqual(0, len([t for t in p.get_write_tags() if t is not core.TAG_DOCUMENT])) self.assertTrue('Name' in r.lines[1]) self.assertTrue('Id' in r.lines[2]) self.assertEqual('\n', r.lines[3])
def test_write_with_wrap(self): """ Tests using an auto-wrap value correctly wraps text. """ # Setup recorder = Recorder() prompt = Prompt(output=recorder, wrap_width=10) # Test prompt.write('-' * 20) # Verify written_lines = recorder.lines[1].split('\n') self.assertEqual(3, len(written_lines)) self.assertEqual('-' * 10, written_lines[0]) self.assertEqual('-' * 10, written_lines[1]) self.assertEqual('', written_lines[2])