Beispiel #1
0
    def ValidateTestDerived(self, obj):
        self.assertEqual(obj.standard_attribute, 10)
        self.assertEqual(obj.variant_attribute, "thirty")

        self.assertEqual(obj.b, False)
        self.assertEqual(obj.d, -100.1)
        self.assertEqual(obj.ref, -200.2)
        self.assertEqual(obj.ref2, 100.1)
        self.assertEqual(obj.ref3, [-10, -20])
        self.assertEqual(obj.ref4, [10, 20])
        self.assertEqual(obj.ref5, [[10.0, 20.0], [30.0, 40.0]])

        self.assertEqual(obj.v1, True)
        self.assertEqual(obj.v2, False)
        self.assertEqual(
            obj.v3[:-1],
            [
                True,
                Uri.FromString("https://test.com"),
                25,
                "10",
                True,
                Uri.FromString("https://another_test.com"),
                "this is a test",
            ],
        )
        self.assertEqual(obj.v3[-1].a, ["one", "two"])

        self.assertEqual(obj.special_variants, [10.0, 20, "thirty"])

        self.assertEqual(obj.any_.one.two.three.a, "a")
        self.assertEqual(obj.any_.one.two.three.b, "b")
        self.assertEqual(obj.any_.one.two.three.simple_value, "value 3")
        self.assertEqual(obj.any_.one.two.four.simple_value, "value 4")
 def ValidateTypes(self, obj):
     self.assertEqual(
         obj.bool_,
         [
             True,
             True,
             True,
             True,
             False,
             False,
             False,
             False,
             True,
             True,
             True,
             False,
             False,
             False,
         ],
     )
     self.assertEqual(
         obj.date_,
         [datetime.date(2019, 2, 11),
          datetime.date(2019, 2, 11)])
     self.assertEqual(obj.datetime_, [
         datetime.datetime(2019, 2, 11, 17, 0, 0),
         datetime.datetime(2019, 2, 11, 17, 0, 0)
     ])
     self.assertEqual([dir.lower() for dir in obj.directory_],
                      [os.path.join(os.getcwd(), "DirectoryName").lower()])
     self.assertEqual(obj.duration_, [
         datetime.timedelta(1, 82862),
         datetime.timedelta(1, 82862, 3),
         datetime.timedelta(0, 82862)
     ])
     self.assertEqual(obj.enum_, ["three", "two", "one"])
     self.assertEqual([filename.lower() for filename in obj.filename_],
                      [os.path.join(os.getcwd(), "FileName").lower()])
     self.assertEqual(
         obj.guid_, [uuid.UUID("f638e451-c276-479a-aaa0-c699e35196fb")] * 4)
     self.assertEqual(obj.int_, [10, -10])
     self.assertEqual(
         obj.number_,
         [
             100.1,
             100.0,
             -100.1,
             -100.0,
         ],
     )
     self.assertEqual(obj.string_, ["test"])
     self.assertEqual(
         obj.time_,
         [datetime.time(10, 11, 12),
          datetime.time(10, 11, 12, 131415)])
     self.assertEqual(obj.uri_, [
         Uri.FromString("https://www.test.com"),
         Uri.FromString("file:///abc123")
     ])
 def Test(value, scheme, host, path, query, credentials, port):
     uri = Uri.FromString(value)
     self.assertEqual(uri.Scheme, scheme)
     self.assertEqual(uri.Host, host)
     self.assertEqual(uri.Path, path)
     self.assertEqual(uri.Query, query)
     self.assertEqual(uri.Credentials, credentials)
     self.assertEqual(uri.Port, port)
 def test_ToString(self):
     self.assertEqual(Uri("https", "foo.bar.com", None).ToString(), "https://foo.bar.com")
     self.assertEqual(Uri("https", "foo.bar.com", "/").ToString(), "https://foo.bar.com/")
     self.assertEqual(Uri("https", "foo.bar.com", None, port=80).ToString(), "https://foo.bar.com:80")
     self.assertEqual(Uri("https", "foo.bar.com", None, credentials=("username", "p@ssword:\\")).ToString(), "https://*****:*****@foo.bar.com")
     self.assertEqual(Uri("https", "foo.bar.com", None, query={ "foo" : "b@r", }).ToString(), "https://foo.bar.com?foo=b%40r")
     self.assertEqual(Uri("https", "foo.bar.com", "p1/p2", query={ "foo" : "b@r", }).ToString(), "https://foo.bar.com/p1/p2?foo=b%40r")
 def test_ConstructErrors(self):
     self.assertRaises(Exception, lambda: Uri("", "foo.bar.com", "/"))
     self.assertRaises(Exception, lambda: Uri("http", "", "/"))