json.loads(response.content), {u("user-agent"): u("Awwparse/0.1-dev")} ) except requests.ConnectionError: self.skip_test("missing internet connection") @skip_if(requests is not None, "requires requests not to be installed") def test_parse_http_fails(self): cli = TestCLI(options=[("foo", Option("-o", Resource()))]) with self.assert_raises(RuntimeError): cli.run(["-o", "http://httpbin.org"]) def test_parse_standard_stream(self): stdin = BytesIO(b"foobar") cli = TestCLI( options=[("foo", Option("-o", Resource()))], stdin=stdin ) opener = cli.run(["-o", "-"])[1]["foo"] with opener as stream: self.assert_equal(stream.read(), b"foobar") suite = make_suite([ StringTestCase, IntegerTestCase, FloatTestCase, DecimalTestCase, ComplexTestCase, BytesTestCase, AnyTestCase, NumberTestCase, ChoiceTestCase, BooleanTestCase, PositionalTestCase, ArgumentsTestCase, NativeStringTestCase, MappingTestCase, FileTestCase, LocalResourceTestCase, ResourceTestCase ])
:copyright: 2012 by Daniel Neuhäuser :license: BSD, see LICENSE.rst for details """ from awwparse import store_last, append_to_list, add_to_set, add, sub from awwparse.testsuite import TestCase, make_suite class ActionsTestCase(TestCase): def test_store_last(self): self.assert_equal(store_last(1, 2), 2) def test_append_to_list(self): self.assert_equal(append_to_list(None, 1), [1]) self.assert_equal(append_to_list([1], 2), [1, 2]) def test_add_to_set(self): self.assert_equal(add_to_set(None, 1), set([1])) self.assert_equal(add_to_set(set([1]), 2), set([1, 2])) def test_add(self): self.assert_equal(add(None, 1), 1) self.assert_equal(add(1, 1), 2) def test_sub(self): self.assert_equal(sub(None, 1), -1) self.assert_equal(sub(1, 1), 0) suite = make_suite([ActionsTestCase])
def __call__(self, a, b): pass signature = Signature.from_object(TestClass()) self.assert_equal(signature.positional_arguments, ["a", "b"]) def test_names(self): def function(a, b, c=None, *args, **kwargs): pass self.assert_equal(Signature.from_function(function).names, ["a", "b", "c", "args", "kwargs"]) class OrderedDictTestCase(TestCase): def test_popitem(self): d = OrderedDict([("foo", 1), ("bar", 2), ("baz", 3)]) self.assert_equal(d.popitem(), ("baz", 3)) self.assert_equal(d, OrderedDict([("foo", 1), ("bar", 2)])) self.assert_equal(d.popitem(last=False), ("foo", 1)) self.assert_equal(d, OrderedDict([("bar", 2)])) def test_move_to_end(self): d = OrderedDict([("foo", 1), ("bar", 2), ("baz", 3)]) d.move_to_end("foo") self.assert_equal(d, OrderedDict([("bar", 2), ("baz", 3), ("foo", 1)])) d.move_to_end("foo", last=False) self.assert_equal(d, OrderedDict([("foo", 1), ("bar", 2), ("baz", 3)])) suite = make_suite([UtilsTestCase, SignatureTestCase, OrderedDictTestCase])
"Positional Arguments\n" " a\n" " b\n" "\n" "Options\n" " -h, --help Show this message\n" ) ) def test_help_option(self): stringio = StringIO() cli = CLI(application_name=u("app"), stdout=stringio, width=40) try: cli.run(["-h"]) except SystemExit: pass self.assert_equal( stringio.getvalue(), u( "Usage: app [-h]\n" "\n" "Options\n" " -h, --help Show this message\n" ) ) suite = make_suite([ OptionTestCase, CommandTestCase, ArgumentsTestCase, CLITestCase ])