Esempio n. 1
0
    def test_present_embeddings_run_server(self):
        def sweded_which(prog):
            return None

        which = shutil.which
        shutil.which = sweded_which
        browser = os.getenv("BROWSER", "")
        os.environ["BROWSER"] = ""

        try:
            with tempfile.TemporaryDirectory(
                    prefix="sourced.ml-test-") as tmpdir:
                with captured_output() as (stdout, _, _):
                    present_embeddings(tmpdir, True, ["one"],
                                       [str(i) for i in range(5)],
                                       [(i, i) for i in range(5)])
                    with open(os.path.join(tmpdir, "id2vec.json")) as fin:
                        json.load(fin)
                    with open(os.path.join(tmpdir, "id2vec_meta.tsv")) as fin:
                        self.assertEqual(fin.read(), "0\n1\n2\n3\n4\n")
                    with open(os.path.join(tmpdir, "id2vec_data.tsv")) as fin:
                        self.assertEqual(fin.read(),
                                         "0\t0\n1\t1\n2\t2\n3\t3\n4\t4\n")
                self.assertIn(
                    "\thttp://projector.tensorflow.org/?config=http://0.0.0.0:8000/id2vec.json\n",
                    stdout.getvalue())
        finally:
            shutil.which = which
            os.environ["BROWSER"] = browser
            web_server.stop()
Esempio n. 2
0
 def test_wait(self):
     web_server.start()
     try:
         attempts, result = self.wait_for_web_server()
         self.assertTrue(attempts < self.MAX_ATTEMPTS or result == 0)
         self.assertTrue(web_server.running)
     except:  # noqa
         web_server.stop()
         raise
     os.environ["PROJECTOR_SERVER_TIME"] = "0"
     wait()
     self.assertFalse(web_server.running)
     web_server.start()
     try:
         attempts, result = self.wait_for_web_server()
         self.assertTrue(attempts < self.MAX_ATTEMPTS or result == 0)
         self.assertTrue(web_server.running)
     finally:
         web_server.stop()
Esempio n. 3
0
 def test_stop(self):
     web_server.stop()  # dummy test to avoid partially covered line in CI
     self.assertFalse(web_server.running)
     web_server.start()
     web_server.stop()
     self.assertFalse(web_server.running)