Example #1
0
    def testUploadDefaultBoth(self):
        other_local_dir = "/tmp/other"
        other_cloud_dir = "memory:///other"

        delete_at_uri(other_cloud_dir)
        self._save_checkpoint_at(other_cloud_dir)
        shutil.copytree(self.local_dir, other_local_dir)

        # Case: Nothing is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        path = checkpoint.upload()

        self.assertEqual(self.cloud_dir, path)

        # Case: Local dir is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        path = checkpoint.upload(local_path=other_local_dir)

        self.assertEqual(self.cloud_dir, path)

        # Case: Both are passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        path = checkpoint.upload(local_path=other_local_dir,
                                 cloud_path=other_cloud_dir)

        self.assertEqual(other_cloud_dir, path)
Example #2
0
    def testUploadDefaultBoth(self):
        state = {}

        def check_call(cmd, *args, **kwargs):
            state["cmd"] = cmd

        other_local_dir = "/tmp/other"
        other_cloud_dir = "s3://other"

        # Case: Nothing is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        with patch("subprocess.check_call", check_call):
            path = checkpoint.upload()

        self.assertEqual(self.cloud_dir, path)
        self.assertEqual(state["cmd"][0], "aws")
        self.assertIn(self.cloud_dir, state["cmd"])

        # Case: Local dir is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        with patch("subprocess.check_call", check_call):
            path = checkpoint.upload(local_path=other_local_dir)

        self.assertEqual(self.cloud_dir, path)
        self.assertEqual(state["cmd"][0], "aws")
        self.assertIn(other_local_dir, state["cmd"])
        self.assertNotIn(self.local_dir, state["cmd"])

        # Case: Both are passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        with patch("subprocess.check_call", check_call):

            path = checkpoint.upload(local_path=other_local_dir,
                                     cloud_path=other_cloud_dir)

        self.assertEqual(other_cloud_dir, path)
        self.assertEqual(state["cmd"][0], "aws")
        self.assertIn(other_local_dir, state["cmd"])
        self.assertNotIn(self.local_dir, state["cmd"])
        self.assertIn(other_cloud_dir, state["cmd"])
        self.assertNotIn(self.cloud_dir, state["cmd"])
Example #3
0
    def testUploadNoDefaults(self):
        state = {}

        def check_call(cmd, *args, **kwargs):
            state["cmd"] = cmd

        # Case: Nothing is passed
        checkpoint = TrialCheckpoint()
        with self.assertRaises(RuntimeError):
            checkpoint.upload()

        # Case: Local dir is passed
        checkpoint = TrialCheckpoint()
        with self.assertRaisesRegex(RuntimeError, "No cloud path"):
            checkpoint.upload(local_path=self.local_dir)

        # Case: Cloud dir is passed
        checkpoint = TrialCheckpoint()
        with self.assertRaisesRegex(RuntimeError, "No local path"):
            checkpoint.upload(cloud_path=self.cloud_dir)

        # Case: Both are passed
        checkpoint = TrialCheckpoint()
        with patch("subprocess.check_call", check_call):
            path = checkpoint.upload(local_path=self.local_dir,
                                     cloud_path=self.cloud_dir)

        self.assertEqual(self.cloud_dir, path)
        self.assertEqual(state["cmd"][0], "aws")
        self.assertIn(self.cloud_dir, state["cmd"])
Example #4
0
    def testUploadDefaultCloud(self):
        other_cloud_dir = "memory:///other"

        delete_at_uri(other_cloud_dir)
        self._save_checkpoint_at(other_cloud_dir)

        # Case: Nothing is passed
        checkpoint = TrialCheckpoint(cloud_path=self.cloud_dir)
        with self.assertRaisesRegex(RuntimeError, "No local path"):
            checkpoint.upload()

        # Case: Local dir is passed
        checkpoint = TrialCheckpoint(cloud_path=self.cloud_dir)
        path = checkpoint.upload(local_path=self.local_dir)

        self.assertEqual(self.cloud_dir, path)

        # Case: Cloud dir is passed
        checkpoint = TrialCheckpoint(cloud_path=self.cloud_dir)
        with self.assertRaisesRegex(RuntimeError, "No local path"):
            checkpoint.upload(cloud_path=other_cloud_dir)

        # Case: Both are passed
        checkpoint = TrialCheckpoint(cloud_path=self.cloud_dir)
        path = checkpoint.upload(local_path=self.local_dir,
                                 cloud_path=other_cloud_dir)

        self.assertEqual(other_cloud_dir, path)
Example #5
0
    def testUploadDefaultLocal(self):
        other_local_dir = "/tmp/invalid"

        # Case: Nothing is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir)
        with self.assertRaisesRegex(RuntimeError, "No cloud path"):
            checkpoint.upload()

        # Case: Local dir is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir)
        with self.assertRaisesRegex(RuntimeError, "No cloud path"):
            checkpoint.upload(local_path=other_local_dir)

        # Case: Cloud dir is passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir)
        path = checkpoint.upload(cloud_path=self.cloud_dir)

        self.assertEqual(self.cloud_dir, path)

        # Case: Both are passed
        checkpoint = TrialCheckpoint(local_path=self.local_dir)
        path = checkpoint.upload(local_path=other_local_dir,
                                 cloud_path=self.cloud_dir)

        self.assertEqual(self.cloud_dir, path)
Example #6
0
    def testUploadNoDefaults(self):
        # Case: Nothing is passed
        checkpoint = TrialCheckpoint()
        with self.assertRaises(RuntimeError):
            checkpoint.upload()

        # Case: Local dir is passed
        checkpoint = TrialCheckpoint()
        with self.assertRaisesRegex(RuntimeError, "No cloud path"):
            checkpoint.upload(local_path=self.local_dir)

        # Case: Cloud dir is passed
        checkpoint = TrialCheckpoint()
        with self.assertRaisesRegex(RuntimeError, "No local path"):
            checkpoint.upload(cloud_path=self.cloud_dir)

        # Case: Both are passed
        checkpoint = TrialCheckpoint()
        path = checkpoint.upload(local_path=self.local_dir,
                                 cloud_path=self.cloud_dir)

        self.assertEqual(self.cloud_dir, path)