# Copyright (C) 2009, Tutorius.org # Copyright (C) 2009, Michael Janelle-Montcalm # Copyright (C) 2009, Vincent Vinet # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import unittest from sugar.tutorius.uam import parse_uri, SchemeError PARSE_SUITE={ #URI SCHEME HOST PARAMS PATH QUERY FRAGMENT "tap://act.tut.org/": ["tap", "act.tut.org","", "/", "", ""], "tap.gtk://a.t.o/0/1": ["tap.gtk","a.t.o","","/0/1","","",""], "tap.gobject://a.t.o/Timer?timeout=5":["tap.gobject","a.t.o","","/Timer","timeout=5",""], } class ParseUriTests(unittest.TestCase): """Tests the UAM parsers""" def test_parse_uri(self): """Test parsing results""" for uri, test in PARSE_SUITE.items(): res = parse_uri(uri) assert res.scheme == test[0], "%s : Expected scheme %s, got %s" % (uri, test[0], res.scheme) assert res.netloc == test[1], "%s : Expected netloc %s, got %s" % (uri, test[1], res.netloc) assert res.params == test[2], "%s : Expected params %s, got %s" % (uri, test[2], res.params) assert res.path == test[3], "%s : Expected path %s, got %s" % (uri, test[3], res.path) assert res.query == test[4], "%s : Expected query %s, got %s" % (uri, test[4], res.query) assert res.fragment == test[5], "%s : Expected fragment %s, got %s" % (uri, test[5], res.fragment) def test_errors(self): """Test exceptions""" try: parse_uri("http://something.org/path") assert False, "Parsing http should fail" except SchemeError: pass try: parse_uri("tap.notarealsubscheme://something.org/path") assert False, "Invalid Subscheme should fail" except SchemeError: pass if __name__ == "__main__": unittest.main()