Skip to content

Commit

Permalink
[incident-32914] Disable worktree unit tests (#31641)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelianR authored Dec 2, 2024
1 parent 8ea4e93 commit 1434b74
Showing 1 changed file with 73 additions and 66 deletions.
139 changes: 73 additions & 66 deletions tasks/unit_tests/libs/common/worktree_tests.py
Original file line number Diff line number Diff line change
@@ -1,97 +1,104 @@
import os
import unittest
# TODO(celian): Reintroduce these tests

from invoke import Context
"""
NOTE: These tests are disabled since they use git commands that are not mocked yet.
This breaks unit tests ran with macos runners.
"""

from tasks.libs.common.git import get_default_branch
from tasks.libs.common.gomodules import get_default_modules
from tasks.libs.common.worktree import agent_context, init_env, is_worktree
# import os
# import unittest

# from invoke import Context

def get_ctx():
return Context()
# from tasks.libs.common.git import get_default_branch
# from tasks.libs.common.gomodules import get_default_modules
# from tasks.libs.common.worktree import agent_context, init_env, is_worktree


class TestWorktree(unittest.TestCase):
def setUp(self):
# Pull only once
init_env(get_ctx(), '6.53.x')
os.environ['AGENT_WORKTREE_NO_PULL'] = '1'
# def get_ctx():
# return Context()

def test_context_is_worktree_true(self):
with agent_context(get_ctx(), '6.53.x'):
self.assertTrue(is_worktree())

def test_context_is_worktree_false(self):
self.assertFalse(is_worktree())
# class TestWorktree(unittest.TestCase):
# def setUp(self):
# # Pull only once
# init_env(get_ctx(), '6.53.x')
# os.environ['AGENT_WORKTREE_NO_PULL'] = '1'

def test_context_nested(self):
with agent_context(get_ctx(), '6.53.x'):
with agent_context(get_ctx(), '6.53.x'):
self.assertTrue(is_worktree())
self.assertTrue(is_worktree())
# def test_context_is_worktree_true(self):
# with agent_context(get_ctx(), '6.53.x'):
# self.assertTrue(is_worktree())

def test_context_pwd(self):
ctx = get_ctx()
# def test_context_is_worktree_false(self):
# self.assertFalse(is_worktree())

with agent_context(ctx, None, skip_checkout=True):
pwdnone = ctx.run('pwd').stdout
# def test_context_nested(self):
# with agent_context(get_ctx(), '6.53.x'):
# with agent_context(get_ctx(), '6.53.x'):
# self.assertTrue(is_worktree())
# self.assertTrue(is_worktree())

with agent_context(ctx, '6.53.x'):
pwd6 = ctx.run('pwd').stdout
# def test_context_pwd(self):
# ctx = get_ctx()

with agent_context(ctx, 'main'):
pwdmain = ctx.run('pwd').stdout
# with agent_context(ctx, None, skip_checkout=True):
# pwdnone = ctx.run('pwd').stdout

self.assertEqual(pwd6, pwdnone)
self.assertEqual(pwd6, pwdmain)
# with agent_context(ctx, '6.53.x'):
# pwd6 = ctx.run('pwd').stdout

def test_context_modules(self):
ctx = get_ctx()
# with agent_context(ctx, 'main'):
# pwdmain = ctx.run('pwd').stdout

with agent_context(ctx, 'main'):
modules7 = get_default_modules()
# self.assertEqual(pwd6, pwdnone)
# self.assertEqual(pwd6, pwdmain)

with agent_context(ctx, '6.53.x'):
modules6 = get_default_modules()
# def test_context_modules(self):
# ctx = get_ctx()

self.assertNotEqual(set(modules6.keys()), set(modules7.keys()))
# with agent_context(ctx, 'main'):
# modules7 = get_default_modules()

def test_context_branch(self):
ctx = get_ctx()
# with agent_context(ctx, '6.53.x'):
# modules6 = get_default_modules()

with agent_context(ctx, 'main'):
branch7 = get_default_branch()
# self.assertNotEqual(set(modules6.keys()), set(modules7.keys()))

with agent_context(ctx, '6.53.x'):
branch6 = get_default_branch()
# def test_context_branch(self):
# ctx = get_ctx()

self.assertNotEqual(branch6, branch7)
# with agent_context(ctx, 'main'):
# branch7 = get_default_branch()

def test_context_no_checkout(self):
ctx = get_ctx()
# with agent_context(ctx, '6.53.x'):
# branch6 = get_default_branch()

with agent_context(ctx, '6.53.x'):
branch6 = get_default_branch()
# self.assertNotEqual(branch6, branch7)

with agent_context(ctx, 'main'):
branch7 = get_default_branch()
# def test_context_no_checkout(self):
# ctx = get_ctx()

with agent_context(ctx, 'main', skip_checkout=True):
branch_no_checkout = get_default_branch()
# with agent_context(ctx, '6.53.x'):
# branch6 = get_default_branch()

self.assertNotEqual(branch6, branch7)
self.assertEqual(branch7, branch_no_checkout)
# with agent_context(ctx, 'main'):
# branch7 = get_default_branch()

def test_context_no_checkout_error(self):
ctx = get_ctx()
# with agent_context(ctx, 'main', skip_checkout=True):
# branch_no_checkout = get_default_branch()

with agent_context(ctx, '6.53.x'):
pass
# self.assertNotEqual(branch6, branch7)
# self.assertEqual(branch7, branch_no_checkout)

def switch_context():
# The current branch is not main
with agent_context(ctx, 'main', skip_checkout=True):
pass
# def test_context_no_checkout_error(self):
# ctx = get_ctx()

self.assertRaises(AssertionError, switch_context)
# with agent_context(ctx, '6.53.x'):
# pass

# def switch_context():
# # The current branch is not main
# with agent_context(ctx, 'main', skip_checkout=True):
# pass

# self.assertRaises(AssertionError, switch_context)

0 comments on commit 1434b74

Please sign in to comment.