コード例 #1
0
def test_read_from_env():
    saved = os.environ
    try:
        os.environ = FakeEnviron(None)
        check_equal(env.read_from_env('FOOBAR'), 0)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('')
        check_equal(env.read_from_env('FOOBAR'), 0)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('???')
        check_equal(env.read_from_env('FOOBAR'), 0)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('1')
        check_equal(env.read_from_env('FOOBAR'), 1)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1))
        check_equal(env.read_float_from_env('FOOBAR'), 1.0)
        #
        os.environ = FakeEnviron('12345678')
        check_equal(env.read_from_env('FOOBAR'), 12345678)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(12345678))
        check_equal(env.read_float_from_env('FOOBAR'), 12345678.0)
        #
        os.environ = FakeEnviron('1234B')
        check_equal(env.read_from_env('FOOBAR'), 1234)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1234))
        check_equal(env.read_float_from_env('FOOBAR'), 1234.0)
        #
        os.environ = FakeEnviron('1.5')
        check_equal(env.read_float_from_env('FOOBAR'), 1.5)
        #
        os.environ = FakeEnviron('1.5Kb')
        check_equal(env.read_from_env('FOOBAR'), 1536)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1536))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('1.5mB')
        check_equal(env.read_from_env('FOOBAR'), int(1.5 * 1024 * 1024))
        check_equal(env.read_uint_from_env('FOOBAR'),
                    r_uint(1.5 * 1024 * 1024))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('1.5g')
        check_equal(env.read_from_env('FOOBAR'), int(1.5 * 1024 * 1024 * 1024))
        check_equal(env.read_uint_from_env('FOOBAR'),
                    r_uint(1.5 * 1024 * 1024 * 1024))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
    finally:
        os.environ = saved
コード例 #2
0
ファイル: test_env.py プロジェクト: sota/pypy
def test_read_from_env():
    saved = os.environ
    try:
        os.environ = FakeEnviron(None)
        check_equal(env.read_from_env('FOOBAR'), 0)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('')
        check_equal(env.read_from_env('FOOBAR'), 0)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('???')
        check_equal(env.read_from_env('FOOBAR'), 0)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(0))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('1')
        check_equal(env.read_from_env('FOOBAR'), 1)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1))
        check_equal(env.read_float_from_env('FOOBAR'), 1.0)
        #
        os.environ = FakeEnviron('12345678')
        check_equal(env.read_from_env('FOOBAR'), 12345678)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(12345678))
        check_equal(env.read_float_from_env('FOOBAR'), 12345678.0)
        #
        os.environ = FakeEnviron('1234B')
        check_equal(env.read_from_env('FOOBAR'), 1234)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1234))
        check_equal(env.read_float_from_env('FOOBAR'), 1234.0)
        #
        os.environ = FakeEnviron('1.5')
        check_equal(env.read_float_from_env('FOOBAR'), 1.5)
        #
        os.environ = FakeEnviron('1.5Kb')
        check_equal(env.read_from_env('FOOBAR'), 1536)
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1536))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('1.5mB')
        check_equal(env.read_from_env('FOOBAR'), int(1.5*1024*1024))
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1.5*1024*1024))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
        os.environ = FakeEnviron('1.5g')
        check_equal(env.read_from_env('FOOBAR'), int(1.5*1024*1024*1024))
        check_equal(env.read_uint_from_env('FOOBAR'), r_uint(1.5*1024*1024*1024))
        check_equal(env.read_float_from_env('FOOBAR'), 0.0)
        #
    finally:
        os.environ = saved
コード例 #3
0
ファイル: generation.py プロジェクト: mozillazg/pypy
def nursery_size_from_env():
    return env.read_from_env('PYPY_GENERATIONGC_NURSERY')
コード例 #4
0
 def post_setup(self):
     # More stuff that needs to be initialized when the GC is already
     # fully working.  (Only called by gctransform/framework for now.)
     from rpython.memory.gc import env
     self.DEBUG = env.read_from_env('PYPY_GC_DEBUG')
コード例 #5
0
ファイル: base.py プロジェクト: timfel/thesis-data
    def post_setup(self):
        # More stuff that needs to be initialized when the GC is already
        # fully working.  (Only called by gctransform/framework for now.)
        from rpython.memory.gc import env

        self.DEBUG = env.read_from_env("PYPY_GC_DEBUG")
コード例 #6
0
ファイル: generation.py プロジェクト: sczfaker/pypy
def nursery_size_from_env():
    return env.read_from_env('PYPY_GENERATIONGC_NURSERY')