예제 #1
0
    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
""")
예제 #2
0
    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)
""")
예제 #3
0
 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__))
예제 #4
0
    def test_reverse(self):
        main(('-r', 'Germany'))
        self.assertMultiLineEqual(self._stdout.getvalue(), """\
Matches for "Germany":
  de: Germany
""")
예제 #5
0
 def test_main_unknown_code(self):
     main(('xx',))
     self.assertEqual(self._output(), 'Where in the world is xx?')
예제 #6
0
 def test_main(self):
     # We also have to capture stderr.
     main(('de',))
     self.assertEqual(self._output(), 'de originates from Germany')
예제 #7
0
 def test_no_domains(self):
     main(())
     output = self._stdout.getvalue().splitlines()
     self.assertEqual(
         output[0].strip(),
         'usage: world [-h] [--version] [-r] [-a] [domain [domain ...]]')
예제 #8
0
 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')
예제 #9
0
 def test_no_reverse_match(self):
     main(('-r', 'freedonia'))
     self.assertEqual(self._output(), 'Where in the world is freedonia?')