def test_reconnect_resets_internal_state(monkeypatch): class FakeDotmeshClient: def __init__(self, cluster_url, username, api_key): self.cluster_url = cluster_url self.username = username self.api_key = api_key def ping(self): pass monkeypatch.setattr(dotscience, "DotmeshClient", FakeDotmeshClient) ds = dotscience.Dotscience() ds.connect("me", "pass", "myproj", "https://example.com") assert ds._dotmesh_client.__dict__ == { "cluster_url": "https://example.com/v2/dotmesh/rpc", "username": "******", "api_key": "pass", } assert ds._project_name == "myproj" # Pretend we have a cached project: ds._cached_project = "not empty" assert ds._get_project_or_create("myproj") == "not empty" # Now, reconnect: ds.connect("me2", "pass2", "myproj2", "https://2.example.com") assert ds._dotmesh_client.__dict__ == { "cluster_url": "https://2.example.com/v2/dotmesh/rpc", "username": "******", "api_key": "pass2", } assert ds._project_name == "myproj2" assert ds._cached_project == None
def test_explicit_script_name(): ds = dotscience.Dotscience() ds.script(TEST_WORKLOAD_FILE) s1 = io.StringIO() ds.publish("Hello", stream=s1) m1 = _parse(s1.getvalue()) assert m1["workload-file"] == TEST_WORKLOAD_FILE
def test_no_script_name_when_interactive(): ds = dotscience.Dotscience() ds.interactive() s1 = io.StringIO() ds.publish("Hello", stream=s1) m1 = _parse(s1.getvalue()) assert "workload-file" not in m1
def test_notice_command_mode(): try: os.environ["DOTSCIENCE_WORKLOAD_TYPE"] = "command" ds = dotscience.Dotscience() ds.publish() assert ds._mode == "script" finally: os.unsetenv("DOTSCIENCE_WORKLOAD_TYPE")
def test_notice_jupyter_mode(): try: os.environ["DOTSCIENCE_WORKLOAD_TYPE"] = "jupyter" ds = dotscience.Dotscience() ds.publish() assert ds._mode == "interactive" finally: os.unsetenv("DOTSCIENCE_WORKLOAD_TYPE")
def test_no_mode(): ds = dotscience.Dotscience() try: ds.publish() except RuntimeError: return True else: assert 'Did not get a RuntimeError when attempting to publish without choosing a mode'
def test_conflicting_mode_2(): ds = dotscience.Dotscience() try: ds.script() ds.interactive() except RuntimeError: return True else: assert 'Did not get a RuntimeError when attempting to conflict modes'
def test_default_script_name(): ds = dotscience.Dotscience() ds.script() s1 = io.StringIO() ds.publish("Hello", stream=s1) m1 = _parse(s1.getvalue()) # This might be a fragile assertion... assert m1["workload-file"].endswith( "/bin/pytest") or m1["workload-file"].endswith("/bin/py.test")
def test_metric_to_summary_backwards_compatibility(): """summary()/add_summary()/add_summaries() backwards compatibility.""" # Run level: r = dotscience.Run("/workspace-root") assert r.summary == r.metric assert r.add_summary == r.add_metric assert r.add_summaries == r.add_metrics # Dotscience level: d = dotscience.Dotscience() assert d.summary == d.metric assert d.add_summary == d.add_metric assert d.add_summaries == d.add_metrics # Module level: assert dotscience.summary == dotscience.metric assert dotscience.add_summary == dotscience.add_metric assert dotscience.add_summaries == dotscience.add_metrics
def test_non_conflicting_mode_2(): ds = dotscience.Dotscience() ds.interactive() ds.interactive() ds.publish()
def test_non_conflicting_mode_1(): ds = dotscience.Dotscience() ds.script() ds.script() ds.publish()