当前位置: 首页>>代码示例>>Python>>正文


Python misc.Provider类代码示例

本文整理汇总了Python中faker.providers.misc.Provider的典型用法代码示例。如果您正苦于以下问题:Python Provider类的具体用法?Python Provider怎么用?Python Provider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Provider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ipv4_network_class

    def test_ipv4_network_class(self):
        from faker.providers.internet import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            klass = provider.ipv4_network_class()
            assert klass in 'abc'
开发者ID:joke2k,项目名称:faker,代码行数:7,代码来源:test_factory.py

示例2: test_ipv4_public

    def test_ipv4_public(self):
        from faker.providers.internet import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            address = provider.ipv4_public()
            address = six.text_type(address)
            assert len(address) >= 7
            assert len(address) <= 15
            assert not ip_address(address).is_private, address
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}$').search(address))

        for _ in range(99):
            address = provider.ipv4_public(network=True)
            address = six.text_type(address)
            assert len(address) >= 9
            assert len(address) <= 18
            # Hack around ipaddress module
            # As 192.0.0.0 is net addr of many 192.0.0.0/* nets
            # ipaddress considers them as private
            if ip_network(address).network_address != ip_address('192.0.0.0'):
                assert not ip_network(address)[0].is_private, address
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$').search(address))
开发者ID:joke2k,项目名称:faker,代码行数:25,代码来源:test_factory.py

示例3: test_no_words_paragraph

    def test_no_words_paragraph(self):
        from faker.providers.lorem import Provider

        provider = Provider(self.generator)

        sentence = provider.sentence(0)
        self.assertEqual(sentence, '')
开发者ID:bessl,项目名称:faker-1,代码行数:7,代码来源:test_factory.py

示例4: test_locale

    def test_locale(self):
        from faker.providers.misc import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            locale = provider.locale()
            self.assertTrue(re.match(r'^[a-z]{2,3}_[A-Z]{2}$', locale))
开发者ID:bessl,项目名称:faker-1,代码行数:7,代码来源:test_factory.py

示例5: test_ipv4

    def test_ipv4(self):
        from faker.providers.internet import Provider

        provider = Provider(self.generator)

        for _ in range(99):
            address = provider.ipv4()
            assert len(address) >= 7
            assert len(address) <= 15
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}$').search(address))

        for _ in range(99):
            address = provider.ipv4(network=True)
            assert len(address) >= 9
            assert len(address) <= 18
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$').search(address))

        address = provider.ipv4(private=True)
        assert len(address) >= 7
        assert len(address) <= 15
        assert (
            re.compile(r'^(\d{1,3}\.){3}\d{1,3}$').search(address))

        address = provider.ipv4(private=False)
        assert len(address) >= 7
        assert len(address) <= 15
        assert (
            re.compile(r'^(\d{1,3}\.){3}\d{1,3}$').search(address))
开发者ID:joke2k,项目名称:faker,代码行数:30,代码来源:test_factory.py

示例6: test_no_words_sentence

    def test_no_words_sentence(self):
        from faker.providers.lorem import Provider

        provider = Provider(self.generator)

        paragraph = provider.paragraph(0)
        assert paragraph == ''
开发者ID:joke2k,项目名称:faker,代码行数:7,代码来源:test_factory.py

示例7: test_nl_BE_ssn_valid

    def test_nl_BE_ssn_valid(self):
        from faker.providers.ssn.nl_BE import Provider

        provider = Provider(None)

        for i in range (1000):
            ssn = provider.ssn()
            self.assertEqual(len(ssn), 11)
            gen_ssn_base = ssn[0:6]
            gen_seq = ssn[6:9]
            gen_chksum = ssn[9:11]
            gen_ssn_base_as_int = int(gen_ssn_base)
            gen_seq_as_int = int(gen_seq)
            gen_chksum_as_int = int(gen_chksum)
            # Check that the sequence nr is between 1 inclusive and 998 inclusive
            self.assertGreater(gen_seq_as_int,0)
            self.assertLessEqual(gen_seq_as_int, 998)

            # validate checksum calculation
            # Since the century is not part of ssn, try both below and above year 2000
            ssn_below = int(ssn[0:9])
            chksum_below = 97 - (ssn_below % 97)
            ssn_above = ssn_below + 2000000000
            chksum_above = 97 - (ssn_above % 97)
            results = [ chksum_above, chksum_below ]
            self.assertIn(gen_chksum_as_int,results)
开发者ID:Stasonhub,项目名称:faker-2,代码行数:26,代码来源:factory.py

示例8: test_no_words_sentence

    def test_no_words_sentence(self):
        from faker.providers.lorem import Provider

        provider = Provider(None)

        paragraph = provider.paragraph(0)
        self.assertEqual(paragraph, '')
开发者ID:Stasonhub,项目名称:faker-2,代码行数:7,代码来源:factory.py

示例9: test_language_code

    def test_language_code(self):
        from faker.providers.misc import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            language_code = provider.language_code()
            self.assertTrue(isinstance(language_code, string_types))
            self.assertTrue(re.match(r'^[a-z]{2,3}$', language_code))
开发者ID:bessl,项目名称:faker-1,代码行数:8,代码来源:test_factory.py

示例10: test_random_pyfloat

    def test_random_pyfloat(self):
        from faker.providers.python import Provider
        provider = Provider(self.generator)

        assert 0 <= abs(provider.pyfloat(left_digits=1)) < 10
        assert 0 <= abs(provider.pyfloat(left_digits=0)) < 1
        x = abs(provider.pyfloat(right_digits=0))
        assert x - int(x) == 0
        with pytest.raises(ValueError):
            provider.pyfloat(left_digits=0, right_digits=0)
开发者ID:joke2k,项目名称:faker,代码行数:10,代码来源:test_factory.py

示例11: test_ipv4_public_class_c

    def test_ipv4_public_class_c(self):
        from faker.providers.internet import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            address = provider.ipv4_public(address_class='c')
            address = six.text_type(address)
            assert len(address) >= 7
            assert len(address) <= 15
            assert not ip_address(address).is_private, address
开发者ID:joke2k,项目名称:faker,代码行数:10,代码来源:test_factory.py

示例12: test_random_pyfloat

    def test_random_pyfloat(self):
        from faker.providers.python import Provider
        provider = Provider(self.generator)

        self.assertTrue(0 <= abs(provider.pyfloat(left_digits=1)) < 10)
        self.assertTrue(0 <= abs(provider.pyfloat(left_digits=0)) < 1)
        x = abs(provider.pyfloat(right_digits=0))
        self.assertTrue(x - int(x) == 0)
        with self.assertRaises(ValueError,
                               msg='A float number cannot have 0 digits '
                               'in total'):
            provider.pyfloat(left_digits=0, right_digits=0)
开发者ID:bessl,项目名称:faker-1,代码行数:12,代码来源:test_factory.py

示例13: test_us_ssn_valid

    def test_us_ssn_valid(self):
        from faker.providers.ssn.en_US import Provider

        provider = Provider(self.generator)
        for i in range(1000):
            ssn = provider.ssn()
            self.assertEqual(len(ssn), 11)
            self.assertNotEqual(ssn[0], '9')
            self.assertNotEqual(ssn[0:3], '666')
            self.assertNotEqual(ssn[0:3], '000')
            self.assertNotEqual(ssn[4:6], '00')
            self.assertNotEqual(ssn[7:11], '0000')
开发者ID:bessl,项目名称:faker-1,代码行数:12,代码来源:test_factory.py

示例14: test_us_ssn_valid

    def test_us_ssn_valid(self):
        from faker.providers.ssn.en_US import Provider

        provider = Provider(self.generator)
        for i in range(1000):
            ssn = provider.ssn()
            assert len(ssn) == 11
            assert ssn[0] != '9'
            assert ssn[0:3] != '666'
            assert ssn[0:3] != '000'
            assert ssn[4:6] != '00'
            assert ssn[7:11] != '0000'
开发者ID:joke2k,项目名称:faker,代码行数:12,代码来源:test_factory.py

示例15: test_password

    def test_password(self):
        from faker.providers.misc import Provider

        def in_string(char, _str):
            return char in _str

        for _ in range(999):
            password = Provider.password()

            self.assertTrue(any([in_string(char, password) for char in "[email protected]#$%^&*()_+"]))
            self.assertTrue(any([in_string(char, password) for char in string.digits]))
            self.assertTrue(any([in_string(char, password) for char in string.ascii_uppercase]))
            self.assertTrue(any([in_string(char, password) for char in string.ascii_lowercase]))

        with self.assertRaises(AssertionError):
            Provider.password(length=2)
开发者ID:Stasonhub,项目名称:faker-2,代码行数:16,代码来源:factory.py


注:本文中的faker.providers.misc.Provider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。