|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# coding=utf-8 |
|
3
|
|
|
from __future__ import division, print_function, unicode_literals |
|
4
|
|
|
|
|
5
|
|
|
import pytest |
|
6
|
|
|
|
|
7
|
|
|
pymongo = pytest.importorskip("pymongo") |
|
8
|
|
|
|
|
9
|
|
|
from sacred.observers.mongo import MongoDbOption, DEFAULT_MONGO_PRIORITY |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
def test_parse_mongo_db_arg(): |
|
13
|
|
|
assert MongoDbOption.parse_mongo_db_arg('foo') == ( |
|
14
|
|
|
'localhost:27017', 'foo', '', DEFAULT_MONGO_PRIORITY) |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
def test_parse_mongo_db_arg_collection(): |
|
18
|
|
|
assert MongoDbOption.parse_mongo_db_arg('foo.bar') == ( |
|
19
|
|
|
'localhost:27017', 'foo', 'bar', DEFAULT_MONGO_PRIORITY) |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
def test_parse_mongo_db_arg_hostname(): |
|
23
|
|
|
assert MongoDbOption.parse_mongo_db_arg('localhost:28017') == \ |
|
24
|
|
|
('localhost:28017', 'sacred', '', DEFAULT_MONGO_PRIORITY) |
|
25
|
|
|
|
|
26
|
|
|
assert MongoDbOption.parse_mongo_db_arg('www.mymongo.db:28017') == \ |
|
27
|
|
|
('www.mymongo.db:28017', 'sacred', '', DEFAULT_MONGO_PRIORITY) |
|
28
|
|
|
|
|
29
|
|
|
assert MongoDbOption.parse_mongo_db_arg('123.45.67.89:27017') == \ |
|
30
|
|
|
('123.45.67.89:27017', 'sacred', '', DEFAULT_MONGO_PRIORITY) |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
def test_parse_mongo_db_arg_hostname_dbname(): |
|
34
|
|
|
assert MongoDbOption.parse_mongo_db_arg('localhost:28017:foo') == \ |
|
35
|
|
|
('localhost:28017', 'foo', '', DEFAULT_MONGO_PRIORITY) |
|
36
|
|
|
|
|
37
|
|
|
assert MongoDbOption.parse_mongo_db_arg('www.mymongo.db:28017:bar') == \ |
|
38
|
|
|
('www.mymongo.db:28017', 'bar', '', DEFAULT_MONGO_PRIORITY) |
|
39
|
|
|
|
|
40
|
|
|
assert MongoDbOption.parse_mongo_db_arg('123.45.67.89:27017:baz') == \ |
|
41
|
|
|
('123.45.67.89:27017', 'baz', '', DEFAULT_MONGO_PRIORITY) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def test_parse_mongo_db_arg_hostname_dbname_collection_name(): |
|
45
|
|
|
assert MongoDbOption.parse_mongo_db_arg('localhost:28017:foo.bar') == \ |
|
46
|
|
|
('localhost:28017', 'foo', 'bar', DEFAULT_MONGO_PRIORITY) |
|
47
|
|
|
|
|
48
|
|
|
assert MongoDbOption.parse_mongo_db_arg('www.mymongo.db:28017:bar.baz') ==\ |
|
49
|
|
|
('www.mymongo.db:28017', 'bar', 'baz', DEFAULT_MONGO_PRIORITY) |
|
50
|
|
|
|
|
51
|
|
|
assert MongoDbOption.parse_mongo_db_arg('123.45.67.89:27017:baz.foo') == \ |
|
52
|
|
|
('123.45.67.89:27017', 'baz', 'foo', DEFAULT_MONGO_PRIORITY) |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
def test_parse_mongo_db_arg_priority(): |
|
56
|
|
|
assert MongoDbOption.parse_mongo_db_arg('localhost:28017:foo.bar!17') == \ |
|
57
|
|
|
('localhost:28017', 'foo', 'bar', 17) |
|
58
|
|
|
|
|
59
|
|
|
assert MongoDbOption.parse_mongo_db_arg('www.mymongo.db:28017:bar.baz!2') ==\ |
|
60
|
|
|
('www.mymongo.db:28017', 'bar', 'baz', 2) |
|
61
|
|
|
|
|
62
|
|
|
assert MongoDbOption.parse_mongo_db_arg('123.45.67.89:27017:baz.foo!-123') == \ |
|
63
|
|
|
('123.45.67.89:27017', 'baz', 'foo', -123) |
|
64
|
|
|
|