Ejemplo n.º 1
0
 def test_reading_failures(self):
     with self.assertRaises(Exception):  # non existing file
         from_file(randstr(8) + '.yaml')
     with self.assertRaises(AssertionError):  # unsupported file extension
         from_file(randstr(10))
     with self.assertRaises(Exception):
         fname = randstr(10) + '.json'
         os.system(f"touch {fname}")
         from_file(fname)
Ejemplo n.º 2
0
 def check_arguments_notebook(self, args):
     self.check_essentials(args)
     assert args.notebook or args.interactive, "must specify a notebook name unless in interactive mode"
     if not args.job_name:
         assert args.notebook or args.interactive, "must specify a notebook if no job name defined"
         args.job_name = os.path.splitext(os.path.basename(
             args.notebook))[0] + "_" + randstr(
             ).hex if args.notebook else "jupyter_server_{}".format(
                 randstr().hex)
     if args.interactive and not args.token:
         to_screen("no authentication token is set", _type="warn")
Ejemplo n.º 3
0
 def test_returning_default(self):
     for dval in [[], ['a', 'b'], {}, {'a': 'b'}]:
         ass_fn = self.assertListEqual if isinstance(
             dval, list) else self.assertDictEqual
         with self.assertRaises(
                 AssertionError):  # unsupported file extension
             from_file(randstr(10))
         fname = randstr(8) + '.yaml'
         ass_fn(from_file(fname, dval), dval)  # non existing
         os.system(f"echo '' > {fname}")
         ass_fn(from_file(fname, dval), dval)
         os.system(f"echo 'abcd' > {fname}")
         ass_fn(from_file(fname, dval), dval)
Ejemplo n.º 4
0
 def check_essentials(self, args):
     assert args.cluster_alias, "must specify a cluster"
     args.sources = [] if not args.sources else args.sources
     args.pip_installs = [] if not args.pip_installs else args.pip_installs
     if args.sources:
         assert args.workspace, "must specify --workspace if --sources used"
         for s in args.sources:
             assert os.path.isfile(s), "file %s not found" % s
     assert args.image, "must specify a docker image"
     if args.job_name:
         args.job_name = args.job_name.replace("$", randstr(10))
Ejemplo n.º 5
0
    def step2_submit_job(self):
        import time
        to_screen("""\
testing REST APIs related to submitting a job, including
- rest_api_submit
        """)
        self.job_name = 'ut_test_' + randstr(10)
        self.cmd_exec([
            'opai', 'job', 'sub', '-i', 'python:3', '-j', self.job_name,
            'opai cluster resources'
        ])
        time.sleep(10)
Ejemplo n.º 6
0
 def test_update_defaults(self):
     # ! not test global defaults updating, test it in integration tests
     test_key, test_value = self.get_random_var_name(), randstr(10)
     # add a default key
     update_default(test_key, test_value, is_global=False, to_delete=False)
     self.assertEqual(
         get_defaults()[test_key],
         test_value,
         msg=f"failed to check {test_key} in {LayeredSettings.as_dict()}")
     # should appear in local
     self.assertEqual(
         from_file(self.local_default_file)[test_key], test_value)
     # delete
     update_default(test_key, test_value, is_global=False, to_delete=True)
     with self.assertRaises(KeyError):
         os.system(f"cat {self.local_default_file}")
         from_file(self.local_default_file, {})[test_key]
     # add not allowed
     test_key = randstr(10)
     update_default(test_key, test_value, is_global=False, to_delete=False)
     with self.assertRaises(KeyError):
         from_file(self.local_default_file, {})[test_key]
Ejemplo n.º 7
0
 def test_unknown_variable_defined(self):
     from openpaisdk import LayeredSettings, __flags__
     test_key, test_value = 'test-key-long-existing', randstr(10)
     __flags__.custom_predefined = [
         {
             'name': test_key,
         },
     ]
     LayeredSettings.reset()
     # ? add / update append key
     LayeredSettings.update('local_default', test_key, test_value)
     # ? reset the predefined
     __flags__.custom_predefined = []
     LayeredSettings.reset()
     self.assertEqual(test_value, LayeredSettings.get(test_key))
     # cannot delete or change the unknown variable
     LayeredSettings.update('local_default', test_key, randstr(10))
     LayeredSettings.reset()
     self.assertEqual(test_value, LayeredSettings.get(test_key))
     LayeredSettings.update('local_default', test_key, delete=True)
     LayeredSettings.reset()
     self.assertEqual(test_value, LayeredSettings.get(test_key))