def test_multiple_reverse_searches(self): main(('-r', 'canada', 'mexico')) self.assertMultiLineEqual(self._stdout.getvalue(), """\ Matches for "canada": ca: Canada Matches for "mexico": mx: Mexico """)
def test_multiple_reverse_matches(self): main(('-r', 'united')) self.assertMultiLineEqual(self._stdout.getvalue(), """\ Matches for "united": ae: United Arab Emirates (the) gb: United Kingdom of Great Britain and Northern Ireland (the) tz: Tanzania, United Republic of uk: United Kingdom (common practice) um: United States Minor Outlying Islands (the) us: United States of America (the) """)
def test_version(self): with self.assertRaises(SystemExit) as cm: main(('--version',)) self.assertEqual(cm.exception.code, 0) # In Python 2, the version string gets written to stderr; in Python 3 # it gets written to stdout. if sys.version_info < (3,): stream = self._stderr else: stream = self._stdout self.assertEqual(self._output(stream), 'world {}'.format(worldlib.__version__))
def test_reverse(self): main(('-r', 'Germany')) self.assertMultiLineEqual(self._stdout.getvalue(), """\ Matches for "Germany": de: Germany """)
def test_main_unknown_code(self): main(('xx',)) self.assertEqual(self._output(), 'Where in the world is xx?')
def test_main(self): # We also have to capture stderr. main(('de',)) self.assertEqual(self._output(), 'de originates from Germany')
def test_no_domains(self): main(()) output = self._stdout.getvalue().splitlines() self.assertEqual( output[0].strip(), 'usage: world [-h] [--version] [-r] [-a] [domain [domain ...]]')
def test_all(self): main(('--all',)) # Rather than test the entire output, just test the first and last. output = self._stdout.getvalue().splitlines() self.assertEqual(output[1].strip(), 'ad: Andorra') self.assertEqual(output[-1].strip(), 'xxx : adult entertainment')
def test_no_reverse_match(self): main(('-r', 'freedonia')) self.assertEqual(self._output(), 'Where in the world is freedonia?')