Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 27310b3

Browse files
committed
[Issue #284] added tests.time_stamp.TimeStamp.test_handling_of_TZ_env_variable
1 parent 6f9e1df commit 27310b3

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def check_ptrack_clean(self, idx_dict, size):
707707
)
708708
)
709709

710-
def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, return_id=True):
710+
def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, return_id=True, env=None):
711711
if not self.probackup_old_path and old_binary:
712712
print('PGPROBACKUPBIN_OLD is not set')
713713
exit(1)
@@ -717,6 +717,9 @@ def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, retur
717717
else:
718718
binary_path = self.probackup_path
719719

720+
if not env:
721+
env=self.test_env
722+
720723
try:
721724
self.cmd = [' '.join(map(str, [binary_path] + command))]
722725
if self.verbose:
@@ -728,13 +731,13 @@ def run_pb(self, command, asynchronous=False, gdb=False, old_binary=False, retur
728731
self.cmd,
729732
stdout=subprocess.PIPE,
730733
stderr=subprocess.PIPE,
731-
env=self.test_env
734+
env=env
732735
)
733736
else:
734737
self.output = subprocess.check_output(
735738
[binary_path] + command,
736739
stderr=subprocess.STDOUT,
737-
env=self.test_env
740+
env=env
738741
).decode('utf-8')
739742
if command[0] == 'backup' and return_id:
740743
# return backup ID
@@ -845,7 +848,8 @@ def backup_node(
845848
self, backup_dir, instance, node, data_dir=False,
846849
backup_type='full', datname=False, options=[],
847850
asynchronous=False, gdb=False,
848-
old_binary=False, return_id=True, no_remote=False
851+
old_binary=False, return_id=True, no_remote=False,
852+
env=None
849853
):
850854
if not node and not data_dir:
851855
print('You must provide ether node or data_dir for backup')
@@ -878,7 +882,7 @@ def backup_node(
878882
if not old_binary:
879883
cmd_list += ['--no-sync']
880884

881-
return self.run_pb(cmd_list + options, asynchronous, gdb, old_binary, return_id)
885+
return self.run_pb(cmd_list + options, asynchronous, gdb, old_binary, return_id, env=env)
882886

883887
def checkdb_node(
884888
self, backup_dir=False, instance=False, data_dir=False,
@@ -942,7 +946,8 @@ def restore_node(
942946

943947
def show_pb(
944948
self, backup_dir, instance=None, backup_id=None,
945-
options=[], as_text=False, as_json=True, old_binary=False
949+
options=[], as_text=False, as_json=True, old_binary=False,
950+
env=None
946951
):
947952

948953
backup_list = []
@@ -963,7 +968,7 @@ def show_pb(
963968

964969
if as_text:
965970
# You should print it when calling as_text=true
966-
return self.run_pb(cmd_list + options, old_binary=old_binary)
971+
return self.run_pb(cmd_list + options, old_binary=old_binary, env=env)
967972

968973
# get show result as list of lines
969974
if as_json:
@@ -988,7 +993,7 @@ def show_pb(
988993
return backup_list
989994
else:
990995
show_splitted = self.run_pb(
991-
cmd_list + options, old_binary=old_binary).splitlines()
996+
cmd_list + options, old_binary=old_binary, env=env).splitlines()
992997
if instance is not None and backup_id is None:
993998
# cut header(ID, Mode, etc) from show as single string
994999
header = show_splitted[1:2][0]

tests/time_stamp.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module_name = 'time_stamp'
99

10-
class CheckTimeStamp(ProbackupTest, unittest.TestCase):
10+
class TimeStamp(ProbackupTest, unittest.TestCase):
1111

1212
def test_start_time_format(self):
1313
"""Test backup ID changing after start-time editing in backup.control.
@@ -81,6 +81,30 @@ def test_server_date_style(self):
8181
# Clean after yourself
8282
self.del_test_dir(module_name, fname)
8383

84+
def test_handling_of_TZ_env_variable(self):
85+
"""Issue #112"""
86+
fname = self.id().split('.')[3]
87+
node = self.make_simple_node(
88+
base_dir="{0}/{1}/node".format(module_name, fname),
89+
set_replication=True,
90+
initdb_params=['--data-checksums'])
91+
92+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
93+
self.init_pb(backup_dir)
94+
self.add_instance(backup_dir, 'node', node)
95+
node.start()
96+
97+
my_env = os.environ.copy()
98+
my_env["TZ"] = "America/Detroit"
99+
100+
self.backup_node(
101+
backup_dir, 'node', node, options=['--stream', '-j 2'], env=my_env)
102+
103+
self.show_pb(backup_dir, 'node', env=my_env)
104+
105+
# Clean after yourself
106+
self.del_test_dir(module_name, fname)
107+
84108
@unittest.skip("skip")
85109
# @unittest.expectedFailure
86110
def test_dst_timezone_handling(self):

0 commit comments

Comments
 (0)