def test_notString(self): """ If something in things is not a string, it is converted into one. """ sample = [1, 2, 'three'] expected = '1, 2, and three' result = util._listToPhrase(sample, 'and') self.assertEqual(expected, result)
def test_threeWords(self): """ With more than two words, the first two are separated by the delimiter. """ sample = ['One', 'Two', 'Three'] expected = 'One, Two, and Three' result = util._listToPhrase(sample, 'and') self.assertEqual(expected, result)
def test_fourWords(self): """ If a delimiter is specified, it is used instead of the default comma. """ sample = ['One', 'Two', 'Three', 'Four'] expected = 'One; Two; Three; or Four' result = util._listToPhrase(sample, 'or', delimiter='; ') self.assertEqual(expected, result)
def test_oneWord(self): """ With a single item, the item is returned. """ sample = ['One'] expected = 'One' result = util._listToPhrase(sample, 'and') self.assertEqual(expected, result)
def test_twoWords(self): """ Two words are separated by the final delimiter. """ sample = ['One', 'Two'] expected = 'One and Two' result = util._listToPhrase(sample, 'and') self.assertEqual(expected, result)
def test_fourWords(self): """ If a delimiter is specified, it is used instead of the default comma. """ sample = ["One", "Two", "Three", "Four"] expected = "One; Two; Three; or Four" result = util._listToPhrase(sample, "or", delimiter="; ") self.assertEqual(expected, result)
def test_empty(self): """ If things is empty, an empty string is returned. """ sample = [] expected = '' result = util._listToPhrase(sample, 'and') self.assertEqual(expected, result)
def test_twoWords(self): """ Two words are separated by the final delimiter. """ sample = ["One", "Two"] expected = "One and Two" result = util._listToPhrase(sample, "and") self.assertEqual(expected, result)
def test_threeWords(self): """ With more than two words, the first two are separated by the delimiter. """ sample = ["One", "Two", "Three"] expected = "One, Two, and Three" result = util._listToPhrase(sample, "and") self.assertEqual(expected, result)
def test_oneWord(self): """ With a single item, the item is returned. """ sample = ["One"] expected = "One" result = util._listToPhrase(sample, "and") self.assertEqual(expected, result)