from .. utils import TranspileTestCase, BuiltinFunctionTestCase


class GlobalsTests(TranspileTestCase):
    def test_simple(self):
        self.assertCodeExecution("""
            print("There are %s globals" % len(globals()))
            x = 1
            y = 'z'
            print("There are %s globals" % len(globals()))

            def method():
                print("In method: there are %s globals" % len(globals()))

                print("globals()['x'] =", globals()['x'])
                print("globals()['y'] =", globals()['y'])
                try:
                    print("globals()['z'] =", globals()['z'])
                except KeyError:
                    print("Variable z not defined")

                globals()[y] = 2

                print("In method: there are %s globals" % len(globals()))

            method()

            print("There are %s globals" % len(globals()))
            print("globals()['x'] =", globals()['x'])
            print("globals()['y'] =", globals()['y'])
            print("globals()['z'] =", globals()['z'])
            print('x', x)
            print('y', y)
            print('z', z)

            print('Done')
        """, run_in_function=False)


class BuiltinGlobalsFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
    functions = ["globals"]

    not_implemented = [
        'test_bool',
        'test_bytearray',
        'test_bytes',
        'test_class',
        'test_complex',
        'test_dict',
        'test_float',
        'test_frozenset',
        'test_int',
        'test_list',
        'test_None',
        'test_NotImplemented',
        'test_range',
        'test_set',
        'test_slice',
        'test_str',
        'test_tuple',
    ]

@@ -1,8 +1,46 @@
+from unittest import expectedFailure%0A%0A
 from .. 
@@ -1237,16 +1237,251 @@
 False)%0A%0A
+    @expectedFailure%0A    def test_preloaded_globals(self):%0A        self.assertCodeExecution(%22%22%22%0A            glbs = globals%0A            x = 1%0A            y = 2%0A%0A            for i in range(10):%0A                print(glbs())%0A        %22%22%22)%0A
 %0Aclass B

add test for globals