Skip to content

Commit 4dfa426

Browse files
committed
Tests use the correct directory for tips
1 parent 5d6e02c commit 4dfa426

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

Infrastructure/PathUtility.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
class PathUtility(object):
66
@staticmethod
7-
def normalize_path(path):
8-
7+
def normalize_path(path, root=sys.argv[0]):
8+
path = path.replace('\\', '/')
99
if not path.startswith("/"):
1010
path = "/" + path
11-
# if sys.frozen == 'macosx_app':
12-
# path = path + "/Resources/"
13-
path = path.replace('\\','/')
14-
result = os.path.dirname(sys.argv[0]) + path
15-
return result
11+
dirname = os.path.dirname(root)
12+
path = dirname + path
13+
path = path.replace('\\', '/')
14+
return path

Infrastructure/TimeSettingsManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def increment_seconds(self, increment = 15):
2121
self.seconds = (self.seconds + increment) % 60
2222
self.fire_time_change_callbacks()
2323

24-
def decrement_seconds(self, decrement=60):
24+
def decrement_seconds(self, decrement=15):
2525
self.seconds = ((self.seconds - decrement) % 60)
2626
self.fire_time_change_callbacks()
2727

Infrastructure/TipsManager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import os, random
22

3+
import sys
4+
35
from Infrastructure.PathUtility import PathUtility
46

57

68
class TipsManager(object):
7-
def __init__(self, seed = None):
9+
def __init__(self, seed = None, root_directory=sys.argv[0]):
10+
self.root_directory = root_directory
811
if seed is not None:
912
random.seed(seed)
1013

1114
def get_random_tip(self):
1215
tips_folder = "Tips"
1316
random_file = random.choice(os.listdir("%s" % tips_folder))
14-
return "{}: {}" .format(random_file, TipsManager.random_line(PathUtility.normalize_path(tips_folder + "\\" + random_file)))
17+
return "{}: {}" .format(random_file, TipsManager.random_line(PathUtility.normalize_path(tips_folder + "\\" + random_file,self.root_directory)))
1518

1619
@staticmethod
1720
def random_line(file_name):

tests/Infrastructure/TimeOptionsManager/TestsTimeOptionsManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_decrement_seconds_3_times_is_10_minutes_45_seconds(self):
5252
time_options_manager.decrement_seconds(1)
5353
time_options_manager.decrement_seconds()
5454
result = time_options_manager.get_time_string()
55-
self.assertEqual(result, "10:16")
55+
self.assertEqual(result, "10:29")
5656

5757
def test_subscribe_to_time_changes(self):
5858
time_options_manager = TimeSettingsManager()

tests/Infrastructure/TipsManager/TestTipsManager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import unittest
22

3+
import sys
4+
35
from Infrastructure.TipsManager import TipsManager
46

57

68
class TestsTipsManage(unittest.TestCase):
79
def test_random_tip_from_file(self):
810
seed = 0
9-
tips_manager = TipsManager(seed)
11+
tips_manager = TipsManager(seed,sys.argv[1])
1012
result = tips_manager.get_random_tip()
1113
self.assertEqual(result, 'TestTips2.txt: Words\n')
1214

1315
def test_random_tip_from_file_second(self):
1416
seed = 1
15-
tips_manager = TipsManager(seed)
17+
tips_manager = TipsManager(seed,sys.argv[1])
1618
result = tips_manager.get_random_tip()
1719
self.assertEqual(result, 'TestTips.txt: Customer collaboration over contract negotiation\n')
1820

0 commit comments

Comments
 (0)