|
28 | 28 | @author: Jens Timmerman (Ghent University) |
29 | 29 | @author: Kenneth Hoste (Ghent University) |
30 | 30 | @author: Maxime Boissonneault (Compute Canada) |
| 31 | +@author: Jan Andre Reuter (Juelich Supercomputing Centre) |
31 | 32 | """ |
32 | 33 | import os |
33 | 34 | import re |
@@ -2895,6 +2896,47 @@ def run_sanity_check_step(sanity_check_paths, enhance_sanity_check): |
2895 | 2896 | run_sanity_check_step({}, False) |
2896 | 2897 | run_sanity_check_step({}, True) |
2897 | 2898 |
|
| 2899 | + def test_create_easyblock_without_logfile(self): |
| 2900 | + """ |
| 2901 | + Test creating an EasyBlock without a logfile. |
| 2902 | + This represents scenarios found in Bundle and QuantumESPRESSO, where an EasyBlock is |
| 2903 | + created within another EasyBlock. |
| 2904 | + """ |
| 2905 | + self.contents = '\n'.join([ |
| 2906 | + 'easyblock = "ConfigureMake"', |
| 2907 | + 'name = "pi"', |
| 2908 | + 'version = "3.14"', |
| 2909 | + 'homepage = "http://example.com"', |
| 2910 | + 'description = "test easyconfig"', |
| 2911 | + 'toolchain = SYSTEM', |
| 2912 | + ]) |
| 2913 | + self.writeEC() |
| 2914 | + # Ensure that the default case works as expected |
| 2915 | + eb = EasyBlock(EasyConfig(self.eb_file)) |
| 2916 | + self.assertNotEqual(eb.log, None) |
| 2917 | + self.assertNotEqual(eb.logfile, None) |
| 2918 | + # Get reference to the actual log instance and ensure that it works |
| 2919 | + # This is NOT eb.log, which represents a separate logger with a separate name. |
| 2920 | + file_log = fancylogger.getLogger(name=None) |
| 2921 | + self.assertNotEqual(getattr(file_log, 'logtofile_%s' % eb.logfile), False) |
| 2922 | + |
| 2923 | + # Now, create another EasyBlock by passing logfile from first EasyBlock. |
| 2924 | + eb_external_logfile = EasyBlock(EasyConfig(self.eb_file), logfile=eb.logfile) |
| 2925 | + self.assertNotEqual(eb_external_logfile.log, None) |
| 2926 | + self.assertTrue(eb_external_logfile.external_logfile) |
| 2927 | + self.assertEqual(eb_external_logfile.logfile, eb.logfile) |
| 2928 | + # Try to log something in it. |
| 2929 | + eb_external_logfile.log.info("Test message") |
| 2930 | + |
| 2931 | + # Try to close EasyBlock with external logfile. This should not affect the logger. |
| 2932 | + eb_external_logfile.close_log() |
| 2933 | + self.assertNotEqual(getattr(file_log, 'logtofile_%s' % eb.logfile), False) |
| 2934 | + # Then close the log from creating EasyBlock. This should work as expected. |
| 2935 | + eb.close_log() |
| 2936 | + self.assertEqual(getattr(file_log, 'logtofile_%s' % eb.logfile), False) |
| 2937 | + |
| 2938 | + os.remove(eb.logfile) |
| 2939 | + |
2898 | 2940 |
|
2899 | 2941 | def suite(): |
2900 | 2942 | """ return all the tests in this file """ |
|
0 commit comments