forked from wandb/wandb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sync.py
More file actions
97 lines (82 loc) · 2.8 KB
/
test_sync.py
File metadata and controls
97 lines (82 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pytest
import os
from click.testing import CliRunner
from threading import Thread
from .api_mocks import upload_logs, upsert_run
from freezegun import freeze_time
import wandb
import time
pytestmark = pytest.mark.skip('sync being update... WIP')
def mock_stop(*args):
pass
def test_watches_for_all_changes(mocker):
with CliRunner().isolated_filesystem():
api = mocker.MagicMock()
sync = wandb.Sync(api, "test", dir='.')
sync.stop = mock_stop
sync.watch(['*'])
with open("some_file.h5", "w") as f:
f.write("My great changes")
# Fuck if I know why this makes shit work...
time.sleep(1)
assert api.upsert_run.called
assert api.push.called
def test_watches_for_specific_change(mocker):
with CliRunner().isolated_filesystem():
api = mocker.MagicMock()
sync = wandb.Sync(api, "test", dir='.')
sync.stop = mock_stop
sync.watch(["rad.txt"])
with open("rad.txt", "a") as f:
f.write("something great")
time.sleep(1)
assert api.push.called
def test_watches_for_subdir_change(mocker):
with CliRunner().isolated_filesystem():
api = mocker.MagicMock()
sync = wandb.Sync(api, "test", dir='.')
sync.stop = mock_stop
sync.watch(["./subdir/*.txt"])
os.mkdir('subdir')
with open("subdir/rad.txt", "a") as f:
f.write("something great")
time.sleep(1)
assert api.push.called
def test_ignores_hidden_folders(mocker):
with CliRunner().isolated_filesystem():
api = mocker.MagicMock()
sync = wandb.Sync(api, "test", dir='.')
sync.stop = mock_stop
sync.watch(["*"])
os.mkdir('.subdir')
with open(".subdir/rad.txt", "a") as f:
f.write("something great")
time.sleep(1)
assert not api.push.called
def test_watches_for_glob_change(mocker):
with CliRunner().isolated_filesystem():
api = mocker.MagicMock()
sync = wandb.Sync(api, "test", dir='.')
sync.stop = mock_stop
sync.watch(["*.txt"])
with open("file.txt", "a") as f:
f.write("great")
time.sleep(1)
assert api.push.called
# def test_syncs_log(mocker, upload_logs, upsert_run, request_mocker):
# with CliRunner().isolated_filesystem():
# api = wandb.Api()
# run_mock = upsert_run(request_mocker)
# with freeze_time("1981-12-09 12:00:01"):
# sync = wandb.Sync(api, dir='.')
# log_mock = upload_logs(request_mocker, sync.run_id)
# sync.stop = mock_stop
# sync.watch('*')
# assert run_mock.called
# print("My logger")
# print("1")
# print("2")
# print("3")
# print("4th and final")
# time.sleep(1)
# assert log_mock.called