|
1
|
|
|
import os |
|
2
|
|
|
import unittest |
|
3
|
|
|
|
|
4
|
|
|
from pyprint.NullPrinter import NullPrinter |
|
5
|
|
|
|
|
6
|
|
|
from coalib.output.printers.LogPrinter import LogPrinter |
|
7
|
|
|
from coalib.output.Tagging import ( |
|
8
|
|
|
delete_tagged_results, get_tag_path, load_tagged_results, tag_results) |
|
9
|
|
|
from tests.TestUtilities import raise_error |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class TaggingTest(unittest.TestCase): |
|
13
|
|
|
|
|
14
|
|
|
def setUp(self): |
|
15
|
|
|
self.log_printer = LogPrinter(NullPrinter()) |
|
16
|
|
|
|
|
17
|
|
|
def test_get_tag_path(self): |
|
18
|
|
|
self.assertEqual(get_tag_path("a", "b", self.log_printer), |
|
19
|
|
|
get_tag_path("a", "b", self.log_printer)) |
|
20
|
|
|
self.assertNotEqual(get_tag_path("a", "b", self.log_printer), |
|
21
|
|
|
get_tag_path("a", "c", self.log_printer)) |
|
22
|
|
|
self.assertNotEqual(get_tag_path("a", "b", self.log_printer), |
|
23
|
|
|
get_tag_path("c", "b", self.log_printer)) |
|
24
|
|
|
|
|
25
|
|
|
def test_tag_results(self): |
|
26
|
|
|
path = get_tag_path("test_tag_create", "test_path", self.log_printer) |
|
27
|
|
|
try: |
|
28
|
|
|
tag_results("test_tag_create", "test_path", {}, self.log_printer) |
|
29
|
|
|
results = load_tagged_results("test_tag_create", |
|
30
|
|
|
"test_path", |
|
31
|
|
|
self.log_printer) |
|
32
|
|
|
self.assertEqual(results, {}) |
|
33
|
|
|
finally: |
|
34
|
|
|
delete_tagged_results("test_tag_create", |
|
35
|
|
|
"test_path", |
|
36
|
|
|
self.log_printer) |
|
37
|
|
|
|
|
38
|
|
|
none_path = get_tag_path("None", "test_path", self.log_printer) |
|
39
|
|
|
tag_results("None", "test_path", {}, self.log_printer) |
|
40
|
|
|
self.assertFalse(os.path.exists(none_path)) |
|
41
|
|
|
results = load_tagged_results("None", "test_path", self.log_printer) |
|
42
|
|
|
self.assertEquals(results, None) |
|
43
|
|
|
|
|
44
|
|
|
def test_delete_tagged_results_no_file(self): |
|
45
|
|
|
path = get_tag_path("test_tag_del", "test_path", self.log_printer) |
|
46
|
|
|
none_path = get_tag_path("None", "test_path", self.log_printer) |
|
47
|
|
|
open(path, "a").close() |
|
48
|
|
|
open(none_path, "a").close() |
|
49
|
|
|
delete_tagged_results("None", "test_path", self.log_printer) |
|
50
|
|
|
self.assertTrue(os.path.exists(none_path)) |
|
51
|
|
|
|
|
52
|
|
|
delete_tagged_results("test_tag_del", "test_path", self.log_printer) |
|
53
|
|
|
self.assertFalse(os.path.exists(path)) |
|
54
|
|
|
|
|
55
|
|
|
delete_tagged_results("test_tag_del2", "test_path", self.log_printer) |
|
56
|
|
|
self.assertFalse(os.path.exists(path)) |
|
57
|
|
|
|
|
58
|
|
|
os.remove(none_path) |
|
59
|
|
|
|
|
60
|
|
|
def test_permission_error(self): |
|
61
|
|
|
old_makedirs = os.makedirs |
|
62
|
|
|
os.makedirs = lambda *args, **kwargs: raise_error(PermissionError) |
|
63
|
|
|
|
|
64
|
|
|
self.assertEqual(get_tag_path("a", "b", self.log_printer), None) |
|
65
|
|
|
tag_results("test_tag", "test_path", {}, self.log_printer) |
|
66
|
|
|
results = load_tagged_results("test_tag", |
|
67
|
|
|
"test_path", |
|
68
|
|
|
self.log_printer) |
|
69
|
|
|
self.assertEqual(results, None) |
|
70
|
|
|
|
|
71
|
|
|
os.makedirs = old_makedirs |
|
72
|
|
|
|