Skip to content

Commit

Permalink
test_dbprocessing: fix on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jtniehof authored and dnadeau-lanl committed Feb 3, 2022
1 parent 858afc2 commit 2ca3554
Showing 1 changed file with 72 additions and 70 deletions.
142 changes: 72 additions & 70 deletions unit_tests/test_dbprocessing.py
Expand Up @@ -7,6 +7,7 @@


import datetime
import os.path
import unittest

import dbp_testing
Expand Down Expand Up @@ -64,8 +65,9 @@ def checkCommandLines(self, fid, expected):
# Sort the input files, identified by having 'data'
# in there (so not argument or output); the order
# of input files doesn't matter. (Don't change function inputs.)
idx_exp = [j for j in range(len(e)) if '/data/' in e[j]]
idx_act = [j for j in range(len(a)) if '/data/' in a[j]]
datapart = os.path.join('x', 'data', 'x')[1:-1]
idx_exp = [j for j in range(len(e)) if datapart in e[j]]
idx_act = [j for j in range(len(a)) if datapart in a[j]]
e = e[:idx_exp[0]] + sorted(e[idx_exp[0]:idx_exp[-1]+1]) \
+ e[idx_exp[-1]+1:]
a = a[:idx_act[0]] + sorted(a[idx_act[0]:idx_act[-1]+1]) \
Expand All @@ -80,9 +82,9 @@ def testSimple(self):
self.addProductProcessLink(l0pid, l01process)
fid = self.addFile('level_0_20120101_v1.0.0', l0pid)
expected = [[
'{}/codes/scripts/junk.py'.format(self.td),
os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0']]
self.checkCommandLines(fid, expected)

Expand All @@ -101,9 +103,9 @@ def testSingleDailyUpdate(self):
#Updated version of L0
fid = self.addFile('level_0_20120101_v1.1.0', l0pid)
expected = [[
'{}/codes/scripts/junk.py'.format(self.td),
os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
'level_1_20120101_v1.1.0']]

def testYesterdayNewFile(self):
Expand All @@ -117,15 +119,15 @@ def testYesterdayNewFile(self):
self.addProductProcessLink(l0pid, l01process, yesterday=1)
l0fid = self.addFile('level_0_20120101_v1.0.0', l0pid)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
'level_1_20120101_v1.0.0'
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'
],
# Yesterday-only is not made
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),,
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
# 'level_1_20120102_v1.0.0'
# ],
]
Expand All @@ -144,31 +146,31 @@ def testYesterdayNewFileTwoDays(self):
l0fid2 = self.addFile('level_0_20120102_v1.0.0', l0pid)
# Precondition: two subsequent L0 days, L1 not made yet.
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'
],
# 2012-01-02 not triggered on "yesterday" even though it has "today"
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
# 'level_1_20120102_v1.0.0'
# ],
]
self.checkCommandLines(l0fid1, expected)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
# Yesterday is included in the command build
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120102_v1.0.0'
],
# 2012-01-03 yesterday-only, not triggered
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
# 'level_1_20120103_v1.0.0'
# ],
]
Expand All @@ -188,15 +190,15 @@ def testYesterdayUpdate(self):
self.dbu.addFilefilelink(l1fid, l0fid)
newfid = self.addFile('level_0_20120101_v1.1.0', l0pid)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
'level_1_20120101_v1.1.0'
],
# Yesterday-only is not made
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
# 'level_1_20120102_v1.0.0'
# ],
]
Expand All @@ -223,16 +225,16 @@ def testYesterdayUpdateTodayExists(self):
# Perturbation: Add new "yesterday"
newfid = self.addFile('level_0_20120101_v1.1.0', l0pid)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
'level_1_20120101_v1.1.0'
],
# Date with only yesterday changed is not updated.
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
# '{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
# 'level_1_20120102_v1.1.0'
# ],
]
Expand All @@ -249,15 +251,15 @@ def testTomorrowNewFile(self):
self.addProductProcessLink(l0pid, l01process, tomorrow=1)
l0fid = self.addFile('level_0_20120101_v1.0.0', l0pid)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'
],
# Tomorrow-only is not made
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
# 'level_1_20111231_v1.0.0'
# ],
]
Expand All @@ -276,32 +278,32 @@ def testTomorrowNewFileTwoDays(self):
l0fid2 = self.addFile('level_0_20120102_v1.0.0', l0pid)
# Precondition: two subsequent L0 days, L1 not made yet.
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
# Tomorrow is included in the command build
'{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'
],
# 2011-12-31 tomorrow-only, not triggered
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
# 'level_1_20111231_v1.0.0'
# ],
]
self.checkCommandLines(l0fid1, expected)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
'level_1_20120102_v1.0.0'
],
# 2012-01-01 not triggered by "tomorrow" even though have "today"
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
# '{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
# 'level_1_20120101_v1.0.0'
# ],
]
Expand All @@ -321,15 +323,15 @@ def testTomorrowUpdate(self):
self.dbu.addFilefilelink(l1fid, l0fid)
newfid = self.addFile('level_0_20120101_v1.1.0', l0pid)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
'level_1_20120101_v1.1.0'
],
# Tomorrow-only is not made
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.1.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.1.0'),
# 'level_1_20111231_v1.0.0'
# ],
]
Expand All @@ -356,16 +358,16 @@ def testTomorrowUpdateTodayExists(self):
# Perturbation: Add new "tomorrow"
newfid = self.addFile('level_0_20120102_v1.1.0', l0pid)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120102_v1.1.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.1.0'),
'level_1_20120102_v1.1.0'
],
# Date with only tomorrow changed is not updated.
# ['{}/codes/scripts/junk.py'.format(self.td),
# [os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
# 'level_0-1_args',
# '{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
# '{}/data/junk/level_0_20120102_v1.1.0'.format(self.td),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
# os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.1.0'),
# 'level_1_20120101_v1.1.0'
# ],
]
Expand All @@ -384,14 +386,14 @@ def testChangeTimebase(self):
[datetime.date(2012, 1, 1), datetime.date(2012, 1, 2)],
self.dbu.getFileDates(fid))
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'],
# l1 "tomorrow" built because l0 "today" includes data for it
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120102_v1.0.0']
]
self.checkCommandLines(fid, expected)
Expand All @@ -415,29 +417,29 @@ def testChangeTimebaseMultiDays(self):
[datetime.date(2012, 1, 2), datetime.date(2012, 1, 3)],
self.dbu.getFileDates(fid2))
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'],
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
# l0 "previous day" with data for l1 "today" is included
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120102_v1.0.0']
]
self.checkCommandLines(fid1, expected)
expected = [
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
# l0 "next day" with data for l1 "today" is included
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120102_v1.0.0'],
# l1 "tomorrow" built because l0 "today" includes data for it
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120102_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120102_v1.0.0'),
'level_1_20120103_v1.0.0']
]
self.checkCommandLines(fid2, expected)
Expand All @@ -456,13 +458,13 @@ def testChangeTimebaseYesterday(self):
self.dbu.getFileDates(fid))
expected = [
# l1 "yesterday" built because l0 "today" includes data for it
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20111231_v1.0.0'],
['{}/codes/scripts/junk.py'.format(self.td),
[os.path.join(self.td, 'codes', 'scripts', 'junk.py'),
'level_0-1_args',
'{}/data/junk/level_0_20120101_v1.0.0'.format(self.td),
os.path.join(self.td, 'data', 'junk', 'level_0_20120101_v1.0.0'),
'level_1_20120101_v1.0.0'],
]
self.checkCommandLines(fid, expected)
Expand Down

0 comments on commit 2ca3554

Please sign in to comment.