Skip to content

Commit

Permalink
Added tests for mepo push, diff, whereis and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed Apr 13, 2024
1 parent 3412ad7 commit f3f521e
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 22 deletions.
5 changes: 5 additions & 0 deletions tests/output/output_diff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Diffing...
FVdycoreCubed_GridComp (location: .):

GEOS_FV3_Utilities.F90
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
7 changes: 7 additions & 0 deletions tests/output/output_push.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

git push https://github.com/GEOS-ESM/FVdycoreCubed_GridComp.git HEAD:<name-of-remote-branch>


9 changes: 9 additions & 0 deletions tests/output/output_reset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Removing src/Components/@FVdycoreCubed_GridComp/@fvdycore...done.
Removing src/Components/@FVdycoreCubed_GridComp...done.
Removing src/Shared/@FMS...done.
Removing src/Shared/@MAPL...done.
Removing src/Shared/@GMAO_Shared...done.
Removing @cmake/@ecbuild...done.
Removing @cmake...done.
Removing @env...done.
Removing mepo state...done.
9 changes: 9 additions & 0 deletions tests/output/output_whereis.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GEOSfvdycore | .
env | @env
cmake | @cmake
ecbuild | @cmake/@ecbuild
GMAO_Shared | src/Shared/@GMAO_Shared
MAPL | src/Shared/@MAPL
FMS | src/Shared/@FMS
FVdycoreCubed_GridComp | src/Components/@FVdycoreCubed_GridComp
fvdycore | src/Components/@FVdycoreCubed_GridComp/@fvdycore
115 changes: 93 additions & 22 deletions tests/test_mepo_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from mepo.command.tag_delete import run as mepo_tag_delete
from mepo.command.fetch import run as mepo_fetch
from mepo.command.pull import run as mepo_pull
from mepo.command.push import run as mepo_push
from mepo.command.diff import run as mepo_diff
from mepo.command.whereis import run as mepo_whereis
from mepo.command.reset import run as mepo_reset

import importlib
mepo_restore_state = importlib.import_module("mepo.command.restore-state")
Expand Down Expand Up @@ -54,10 +58,22 @@ def __copy_config_file(cls):
dst = os.path.join(cls.fixture_dir)
shutil.copy(src, dst)

@classmethod
def __mepo_clone(cls):
# mepo clone
args.style = 'prefix'
args.regsitry = None
args.repo_url = None
args.branch = None
args.directory = None
args.partial = 'blobless'
mepo_clone(args)

@classmethod
def setUpClass(cls):
cls.input_dir = os.path.join(THIS_DIR, 'input')
cls.output_dir = os.path.join(THIS_DIR, 'output')
cls.output_clone_status = cls.__get_saved_output("output_clone_status.txt")
cls.fixture = 'GEOSfvdycore'
cls.tag = 'v1.13.0'
cls.tmpdir = os.path.join(THIS_DIR, 'tmp')
Expand All @@ -66,33 +82,30 @@ def setUpClass(cls):
shutil.rmtree(cls.fixture_dir)
cls.__checkout_fixture()
os.chdir(cls.fixture_dir)
# mepo clone
args.style = 'prefix'
args.regsitry = None
args.repo_url = None
args.branch = None
args.directory = None
args.partial = 'blobless'
mepo_clone(args)
cls.__mepo_clone()

def setUp(self):
pass

def __check_status(self, saved_output_file):
def __mepo_status(self, saved_output):
'''saved_output is either a string or a filename'''
os.chdir(self.__class__.fixture_dir)
args.ignore_permissions = False
args.nocolor = True
args.hashes = False
sys.stdout = output = StringIO()
args.ignore_permissions=False
args.nocolor=True
args.hashes=False
mepo_status(args)
sys.stdout = sys.__stdout__
saved_output = self.__class__.__get_saved_output(saved_output_file)
self.assertEqual(output.getvalue(), saved_output)
try:
self.assertEqual(output.getvalue(), saved_output)
except:
saved_output = self.__class__.__get_saved_output(saved_output)
self.assertEqual(output.getvalue(), saved_output)

def __restore_state(self):
def __mepo_restore_state(self):
os.chdir(self.__class__.fixture_dir)
mepo_restore_state.run(args)
self.__check_status("output_clone_status.txt")
self.__mepo_status(self.__class__.output_clone_status)

def test_list(self):
os.chdir(self.__class__.fixture_dir)
Expand All @@ -106,10 +119,12 @@ def test_develop(self):
os.chdir(self.__class__.fixture_dir)
args.comp_name = ["env", "cmake", "fvdycore"]
args.quiet = False
sys.stdout = output = StringIO() # suppressing output to stdout
mepo_develop(args)
self.__check_status("output_develop_status.txt")
sys.stdout = sys.__stdout__
self.__mepo_status("output_develop_status.txt")
# Clean up
self.__restore_state()
self.__mepo_restore_state()

def test_checkout_compare(self):
os.chdir(self.__class__.fixture_dir)
Expand Down Expand Up @@ -137,7 +152,7 @@ def test_checkout_compare(self):
saved_output = self.__class__.__get_saved_output("output_compare_all.txt")
self.assertEqual(output.getvalue(), saved_output)
# Clean up
self.__restore_state()
self.__mepo_restore_state()

def test_checkout_if_exists(self):
os.chdir(self.__class__.fixture_dir)
Expand All @@ -147,7 +162,7 @@ def test_checkout_if_exists(self):
args.dry_run = False
mepo_checkout_if_exists.run(args)
# Since we do not expect this ref to exist, status should be that of clone
self.__check_status("output_clone_status.txt")
self.__mepo_status(self.__class__.output_clone_status)

def test_branch_list(self):
os.chdir(self.__class__.fixture_dir)
Expand Down Expand Up @@ -220,7 +235,6 @@ def test_fetch(self):
self.assertEqual(output.getvalue(), saved_output)

def test_pull(self):
# TODO: compare output
os.chdir(self.__class__.fixture_dir)
args.comp_name = ["FVdycoreCubed_GridComp"]
args.quiet = False
Expand All @@ -229,7 +243,6 @@ def test_pull(self):
mepo_pull(args)

def test_pull_all(self):
# TODO: compare output
os.chdir(self.__class__.fixture_dir)
args.comp_name = ["FVdycoreCubed_GridComp"]
args.quiet = False
Expand All @@ -239,6 +252,64 @@ def test_pull_all(self):
saved_output = self.__class__.__get_saved_output("output_pull_all.txt")
self.assertEqual(output.getvalue(), saved_output)

def test_push(self):
os.chdir(self.__class__.fixture_dir)
args.comp_name = ["FVdycoreCubed_GridComp"]
args.quiet = False
sys.stdout = output = StringIO()
with self.assertRaises(sp.CalledProcessError):
mepo_push(args)
sys.stdout = sys.__stdout__
saved_output = self.__class__.__get_saved_output("output_push.txt")
self.assertEqual(output.getvalue(), saved_output)

def test_diff(self):
os.chdir(self.__class__.fixture_dir)
os.chdir("./src/Components/@FVdycoreCubed_GridComp")
filename = "GEOS_FV3_Utilities.F90"
# Add a line
with open(filename, "w") as fout:
fout.write(" ")
args.comp_name = ["FVdycoreCubed_GridComp"]
args.name_only = True
args.name_status = False
args.ignore_permissions = False
args.staged = False
args.ignore_space_change = False
sys.stdout = output = StringIO()
mepo_diff(args)
sys.stdout = sys.__stdout__
saved_output = self.__class__.__get_saved_output("output_diff.txt")
self.assertEqual(output.getvalue(), saved_output)
# Clean up
sp.run(f"git checkout {filename}".split())
self.__mepo_status(self.__class__.output_clone_status)

def test_whereis(self):
os.chdir(self.__class__.fixture_dir)
args.comp_name = None
args.ignore_case = False
sys.stdout = output = StringIO()
mepo_whereis(args)
sys.stdout = sys.__stdout__
saved_output = self.__class__.__get_saved_output("output_whereis.txt")
self.assertEqual(output.getvalue(), saved_output)

def test_reset(self):
os.chdir(self.__class__.fixture_dir)
args.force = True
args.reclone = False
args.dry_run = False
sys.stdout = output = StringIO()
mepo_reset(args)
sys.stdout = sys.__stdout__
saved_output = self.__class__.__get_saved_output("output_reset.txt")
self.assertEqual(output.getvalue(), saved_output)
# Clean up - reclone (suppress output)
sys.stdout = output = StringIO()
self.__class__.__mepo_clone()
sys.stdout = sys.__stdout__

def tearDown(self):
pass

Expand Down

0 comments on commit f3f521e

Please sign in to comment.