예제 #1
0
 def test_already_exists(self):
     sql = intermix.annotate(
         '/* INTERMIX_ID: deadbeef */ select * from users;',
         'test_app\u0203',
         1,
         dag='test€',
         task='nested',
         override=False)
     self.assertEqual('/* INTERMIX_ID: deadbeef */ select * from users;',
                      sql)
예제 #2
0
 def test_basic_SQL(self):
     expected = BASE_ANNOTATION.copy()
     expected.update({
         'function': 'test_basic_SQL',
         'task': 'test_basic_SQL',
         'dag': 'in_a_class',
         'app': 'test_app',
         'linenumber': '60',
         'classname': 'IntermixTest'
     })
     annotated = decoder(
         intermix.annotate('select € from users;',
                           'test_app',
                           1,
                           dag='in_a_class',
                           task='test_basic_SQL'))
     del annotated['at']
     self.assertDictEqual(expected, annotated)
예제 #3
0
 def test_static_method():
     expected = BASE_ANNOTATION.copy()
     expected.update({
         'function': 'test_static_method',
         'task': 'static_method',
         'dag': 'in_a_class',
         'app': 'test_app',
         'linenumber': '42',
         'classname': ''
     })
     annotated = decoder(
         intermix.annotate('select * from users;',
                           'test_app',
                           1,
                           dag='in_a_class',
                           task='static_method'))
     del annotated['at']
     helper.assertDictEqual(expected, annotated)
예제 #4
0
 def test_already_exists_overridden(self):
     expected = BASE_ANNOTATION.copy()
     expected.update({
         'function': 'test_already_exists_overridden',
         'task': 'overriden',
         'dag': 'test€',
         'app': 'test_app\u0203',
         'linenumber': '85',
         'classname': 'IntermixTest'
     })
     annotated = decoder(
         intermix.annotate(
             '/* INTERMIX_ID: deadbeef */ select * from users;',
             'test_app\u0203',
             1,
             dag='test€',
             task='overriden'))
     del annotated['at']
     self.assertDictEqual(expected, annotated)
예제 #5
0
def test_bare_function():
    """ We want to test annotations in a function outside of a class """
    # Helper to access asserts
    expected = BASE_ANNOTATION.copy()
    expected.update({
        'function': 'test_bare_function',
        'task': 'function',
        'dag': 'bare',
        'app': 'test_app',
        'linenumber': '96',
        'classname': ''
    })
    annotated = decoder(
        intermix.annotate('select * from users;',
                          'test_app',
                          1,
                          dag='bare',
                          task='function'))
    del annotated['at']
    helper.assertDictEqual(expected, annotated)
예제 #6
0
 def foo():
     return intermix.annotate('select * from users;',
                              'test_app',
                              '2',
                              dag='in_a_class',
                              task='nested')
예제 #7
0
                          dag='bare',
                          task='function'))
    del annotated['at']
    helper.assertDictEqual(expected, annotated)


if __name__ == '__main__':
    # Test code running outside of function
    helper = unittest.FunctionTestCase(lambda: None)
    expected = BASE_ANNOTATION.copy()
    expected.update({
        'function': '<module>',
        'task': 'outside_of_function',
        'dag': 'bare',
        'app': 'test_app',
        'linenumber': '108',
        'classname': ''
    })
    annotated = decoder(
        intermix.annotate('select * from users;',
                          'test_app',
                          1,
                          dag='bare',
                          task='outside_of_function'))
    del annotated['at']
    helper.assertDictEqual(expected, annotated)

    unittest.FunctionTestCase(test_bare_function).debug()

    unittest.main()