mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-25 23:09:49 +01:00
Windows symlink: fix executor tests and small bugs
This commit is contained in:
+2
-8
@@ -45,13 +45,13 @@ class System(object):
|
||||
if not os.path.isfile(path):
|
||||
return False
|
||||
|
||||
return System._get_symlink_string() is not None
|
||||
return System._get_symlink_string(path) is not None
|
||||
|
||||
@staticmethod
|
||||
def _get_symlink_string(path):
|
||||
code, output, _ = Executor.exec_cmd(["dir", path], shell=True)
|
||||
if code != 0:
|
||||
return False
|
||||
return None
|
||||
|
||||
lines = output.split('\n')
|
||||
for line in lines:
|
||||
@@ -77,12 +77,6 @@ class System(object):
|
||||
resolved_link = groups[0][1:-1]
|
||||
return resolved_link
|
||||
|
||||
@staticmethod
|
||||
def ls_command_name():
|
||||
if System.is_unix():
|
||||
return 'ls'
|
||||
return 'dir'
|
||||
|
||||
@staticmethod
|
||||
def get_long_path(path):
|
||||
"""Convert short path to a full path. It is needed for Windows."""
|
||||
|
||||
@@ -133,7 +133,8 @@ class TestDataPathInDataDir(BasicEnvironment):
|
||||
self.assertEqual(self.data_path.state.abs, target)
|
||||
|
||||
def test_symlink(self):
|
||||
self.assertEqual(self.data_path._symlink_file, '../../../ca/dir1/d2/file.txt_eeeff8f')
|
||||
expected = os.path.join('..', '..', '..', 'ca', 'dir1', 'd2', 'file.txt_eeeff8f')
|
||||
self.assertEqual(self.data_path._symlink_file, expected)
|
||||
|
||||
def test_data_dir(self):
|
||||
data_path = self.path_factory.data_item(self.data_dir)
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestDvcPathTest(TestCase):
|
||||
self.assertEqual(path.dvc, dvc_file_name)
|
||||
self.assertEqual(path.filename, os.path.basename(dvc_file_name))
|
||||
self.assertEqual(path.relative, relative_file_name)
|
||||
self.assertTrue(os.path.isabs(path.abs[0]))
|
||||
self.assertTrue(os.path.isabs(path.abs))
|
||||
self.assertTrue(path.abs.endswith(dvc_file_name))
|
||||
|
||||
def basic_test(self):
|
||||
|
||||
+13
-30
@@ -11,50 +11,33 @@ class TestExecutor(TestCase):
|
||||
def setUp(self):
|
||||
self.test_dir = System.get_long_path(tempfile.mkdtemp())
|
||||
|
||||
self.file1 = 'file1.txt'
|
||||
fd1 = open(os.path.join(self.test_dir, self.file1), 'w+')
|
||||
fd1.write('this is file 1')
|
||||
fd1.close()
|
||||
|
||||
self.file2 = 'f.csv'
|
||||
fd2 = open(os.path.join(self.test_dir, self.file2), 'w+')
|
||||
fd2.write('this is file 222')
|
||||
fd2.close()
|
||||
self.code_file = 'myfile.py'
|
||||
fd = open(self.code_file, 'w')
|
||||
fd.write('import sys\nsys.stdout.write("111")\nsys.stderr.write("222")\n')
|
||||
fd.close()
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.test_dir)
|
||||
|
||||
def test_suppress_output(self):
|
||||
output = Executor.exec_cmd_only_success([System.ls_command_name(), self.test_dir],
|
||||
shell=True,
|
||||
cwd=self.test_dir)
|
||||
output_set = set(output.split())
|
||||
self.assertEqual(output_set, {self.file1, self.file2})
|
||||
output = Executor.exec_cmd_only_success(['python', self.code_file])
|
||||
self.assertEqual(output, '111')
|
||||
|
||||
def test_output_to_std_console(self):
|
||||
output = Executor.exec_cmd_only_success([System.ls_command_name(), self.test_dir],
|
||||
'-',
|
||||
'-',
|
||||
shell=True)
|
||||
# This output "111" in stdout and "222" are not suppressible.
|
||||
# You will see the outputs when the unit-test runs.
|
||||
output = Executor.exec_cmd_only_success(['python', self.code_file], '-', '-')
|
||||
self.assertEqual(output, '')
|
||||
|
||||
def test_custom_file_outputs(self):
|
||||
stdout_file = os.path.join(self.test_dir, 'stdout.txt')
|
||||
stderr_file = os.path.join(self.test_dir, 'stderr.txt')
|
||||
output = Executor.exec_cmd_only_success([System.ls_command_name(), self.test_dir],
|
||||
stdout_file,
|
||||
stderr_file,
|
||||
shell=True,
|
||||
cwd=self.test_dir)
|
||||
|
||||
output = Executor.exec_cmd_only_success(['python', self.code_file], stdout_file, stderr_file)
|
||||
|
||||
self.assertEqual(output, '')
|
||||
|
||||
output_set = set(open(stdout_file).read().split())
|
||||
expected = {self.file1,
|
||||
self.file2,
|
||||
os.path.basename(stdout_file),
|
||||
os.path.basename(stderr_file)}
|
||||
self.assertEqual(output_set, expected)
|
||||
self.assertEqual(open(stdout_file).read(), "111")
|
||||
self.assertEqual(open(stderr_file).read(), "222")
|
||||
|
||||
os.remove(stdout_file)
|
||||
os.remove(stderr_file)
|
||||
|
||||
Reference in New Issue
Block a user