File indexing completed on 2026-10-08 08:36:30
0001 """Offline onboarding-doc and data-path regressions; no BNL/ROOT/submission."""
0002 import os
0003 from pathlib import Path
0004 import shutil
0005 import subprocess
0006 import tempfile
0007 import unittest
0008
0009 ROOT = Path(__file__).resolve().parents[2]
0010 DEFAULT_DATA = '/gpfs01/star/pwg/pnord/eic/2026TBdata/raw'
0011
0012
0013 class OnboardingTests(unittest.TestCase):
0014 def test_tldr_link_is_at_top_of_setup(self):
0015 lines = (ROOT/'examples/yall/SETUP.md').read_text().splitlines()
0016 self.assertIn('(SETUP_TLDR.md)', '\n'.join(lines[:6]))
0017 self.assertTrue((ROOT/'examples/yall/SETUP_TLDR.md').is_file())
0018
0019 def test_tldr_leads_with_fresh_install_and_links_existing_install(self):
0020 text = (ROOT/'examples/yall/SETUP_TLDR.md').read_text()
0021 self.assertIn('## New installation: start here', text)
0022 self.assertIn('curl -fL https://raw.githubusercontent.com/paulnord/epic-lfhcal-tbana/yall-integration-upstream/tools/bootstrap-yall-integration.sh', text)
0023 self.assertIn('LFHCAL_BRANCH=yall-integration-upstream', text)
0024 self.assertIn('(EXISTING_INSTALL.md)', text)
0025 self.assertIn('9 completed tasks', text)
0026 self.assertIn('%preflight', text)
0027 self.assertIn('-j 1', text)
0028
0029 def test_defaults_match_and_do_not_canonicalize_mount_alias(self):
0030 for relative in ('tools/bootstrap-yall-integration.sh',
0031 'examples/yall/lfhcal-simple/env-eic.sh'):
0032 text = (ROOT/relative).read_text()
0033 self.assertIn(DEFAULT_DATA, text)
0034 self.assertNotIn('/gpfs/mnt', text)
0035
0036 def test_guides_name_the_raw_subdirectory(self):
0037 for name in ('SETUP.md', 'SETUP_TLDR.md'):
0038 text = (ROOT/'examples/yall'/name).read_text()
0039 self.assertIn(DEFAULT_DATA, text)
0040
0041 def source_eic_environment(self, raw_override=None):
0042 with tempfile.TemporaryDirectory() as d:
0043 workspace = Path(d)
0044 example = workspace/'epic-lfhcal-tbana/examples/yall/lfhcal-simple'
0045 example.mkdir(parents=True)
0046 script = example/'env-eic.sh'
0047 shutil.copy2(ROOT/'examples/yall/lfhcal-simple/env-eic.sh', script)
0048 package = workspace/'yall-run/src/yall_run'
0049 package.mkdir(parents=True)
0050 (package/'__init__.py').write_text('')
0051 (package/'cli.py').write_text('print("test-yall")\n')
0052 env = {k:v for k,v in os.environ.items()
0053 if not k.startswith(('LFHCAL_', 'YALL_', 'EIC_', 'PYTHONPATH'))}
0054 env['LFHCAL_WORK'] = str(workspace/'work')
0055 if raw_override is not None:
0056 env['LFHCAL_DATA'] = raw_override
0057 result = subprocess.run(['bash', '-c',
0058 'source "$1" || exit $?; printf "SELECTED_RAW=%s\\n" "$LFHCAL_DATA"',
0059 'source-test', str(script)], env=env, text=True, capture_output=True)
0060 self.assertEqual(result.returncode, 0, result.stdout+result.stderr)
0061 self.assertTrue((workspace/'work/campaigns').is_dir())
0062 return next(line.split('=',1)[1] for line in result.stdout.splitlines()
0063 if line.startswith('SELECTED_RAW='))
0064
0065 def test_eic_default_uses_short_mount_path(self):
0066 self.assertEqual(self.source_eic_environment(), DEFAULT_DATA)
0067
0068 def test_eic_preserves_explicit_user_data_path(self):
0069 self.assertEqual(self.source_eic_environment('/custom/raw-input'), '/custom/raw-input')
0070
0071 def test_documented_one_time_fix_preserves_other_settings_and_backup(self):
0072 text = (ROOT/'examples/yall/SETUP.md').read_text()
0073 command = next(line for line in text.splitlines() if line.startswith('sed -i.bnl-raw-backup '))
0074 parent = str(Path(DEFAULT_DATA).parent)
0075 variants = (parent, '/gpfs/mnt'+parent, DEFAULT_DATA,
0076 '/gpfs/mnt'+DEFAULT_DATA, '/custom/raw-input', parent+'/converted')
0077 for old in variants:
0078 with self.subTest(old=old), tempfile.TemporaryDirectory() as d:
0079 original = ('if (! $?LFHCAL_DATA) setenv LFHCAL_DATA "'+old+'"\n'
0080 'setenv LFHCAL_WORK "/my/existing/output"\n# keep this comment\n')
0081 site = Path(d)/'site-env.tcsh'
0082 site.write_text(original)
0083 env = dict(os.environ, LFHCAL_HOME=d)
0084 subprocess.run(['bash','-c',command],env=env,check=True)
0085 expected = original if old in variants[-2:] else original.replace(old,DEFAULT_DATA)
0086 self.assertEqual(site.read_text(),expected)
0087 self.assertEqual(Path(str(site)+'.bnl-raw-backup').read_text(),original)
0088 self.assertNotIn('/raw/raw',site.read_text())
0089
0090
0091 if __name__ == '__main__':
0092 unittest.main()