Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sync_runs(runner, request_mocker, upsert_run, upload_url, upload_logs, query_viewer, git_repo):
os.environ["WANDB_API_KEY"] = "some invalid key"
query_viewer(request_mocker)
upsert_run(request_mocker)
upload_url(request_mocker)
upload_logs(request_mocker, "abc123zz")
upload_logs(request_mocker, "cba321zz")
run_1 = "wandb/run-120199-abc123zz"
run_2 = "wandb/dryrun-120300-cba321zz"
wandb.util.mkdir_exists_ok(run_1)
wandb.util.mkdir_exists_ok(run_2)
with open(run_1 + "/wandb-history.jsonl", "w") as f:
f.write('{"acc":25}')
with open(run_2 + "/wandb-history.jsonl", "w") as f:
f.write('{"acc":25}')
result = runner.invoke(cli.sync, ".")
print(result.output)
print(result.exception)
print(traceback.print_tb(result.exc_info[2]))
found = re.findall(r"Uploading history metrics", str(result.output))
assert len(found) == 2
def test_sync_tensorboard_ignore(runner, git_repo, mock_server):
# Un comment this line when re-recording the cassette
os.environ['WANDB_API_KEY'] = DUMMY_API_KEY
wandb.util.mkdir_exists_ok("logs/train")
wandb.util.mkdir_exists_ok("logs/val")
with open("logs/garbage.txt", "w") as f:
f.write("NOTHING")
tf_events="events.out.tfevents.111.test.localdomain"
shutil.copyfile(os.path.dirname(__file__) + "/fixtures/"+tf_events, "./logs/train/"+tf_events)
shutil.copyfile(os.path.dirname(__file__) + "/fixtures/"+tf_events, "./logs/val/"+tf_events)
result = runner.invoke(cli.sync, ["--id", "abc123", "-e", "vanpelt", "--ignore", "garbage.txt", "logs"], env=os.environ)
print(result.output)
print(result.exception)
print(traceback.print_tb(result.exc_info[2]))
assert "Found tfevents file, converting..." in str(result.output)
assert result.exit_code == 0
def history():
with CliRunner().isolated_filesystem():
wandb.run = wandb.wandb_run.Run.from_environment_or_defaults()
wandb.util.mkdir_exists_ok(wandb.run.dir)
yield wandb.run.history
wandb.run = None
def test_sync_tensorboard_single(runner, git_repo, mock_server):
# Un comment this line when re-recording the cassette
os.environ['WANDB_API_KEY'] = DUMMY_API_KEY
wandb.util.mkdir_exists_ok("logs")
tf_events="events.out.tfevents.111.simple.localdomain"
shutil.copyfile(os.path.dirname(__file__) + "/fixtures/"+tf_events, "./logs/"+tf_events)
result = runner.invoke(cli.sync, ["--id", "abc123", "-e", "vanpelt", "logs"], env=os.environ)
print(result.output)
print(result.exception)
print(traceback.print_tb(result.exc_info[2]))
assert "Found tfevents file, converting..." in str(result.output)
assert "WARNING Not logging key \"histo\"" in str(result.output)
assert result.exit_code == 0
print(mock_server.requests["file_stream"][0]["files"]["wandb-history.jsonl"]["content"])
assert len(json.loads(mock_server.requests["file_stream"][0]["files"]["wandb-history.jsonl"]["content"][0]).keys()) == 5
def _local_path():
util.mkdir_exists_ok(wandb_dir())
return os.path.join(wandb_dir(), 'settings')
def _global_path():
config_dir = os.environ.get(env.CONFIG_DIR, os.path.join(os.path.expanduser("~"), ".config", "wandb"))
util.mkdir_exists_ok(config_dir)
return os.path.join(config_dir, 'settings')
def prepare_file(self):
if self.copy:
self.save_path = os.path.join(TMP_DIR.name, self.save_name)
wandb.util.mkdir_exists_ok(os.path.dirname(self.save_path))
shutil.copy2(self.path, self.save_path)
def run(self):
# The process
if self._id is None:
self._id = wandb_run.generate_id()
if self._dir is None:
self._dir = wandb_run.run_dir_path(self._id, dry=False)
util.mkdir_exists_ok(self._dir)
if self._message:
open(os.path.join(dir, 'description.md'),
'w').write('%s\n' % self._message)
# setup child environment
env = copy.copy(os.environ)
# tell child python interpreters we accept utf-8
# TODO(adrian): is there a language-agnostic way of doing this?
env['PYTHONIOENCODING'] = 'UTF-8'
env['WANDB_MODE'] = 'run'
env['WANDB_RUN_ID'] = self._id
env['WANDB_RUN_DIR'] = self._dir
if self._configs:
env['WANDB_CONFIG_PATHS'] = self._configs
if self._show:
env['WANDB_SHOW_RUN'] = '1'
def _mkdir(self):
util.mkdir_exists_ok(self._dir)