예제 #1
0
    def test_exists_true_false(self, exists):
        exists.return_value = False
        field = FilenameField(exists=True)
        with pytest.raises(ValueError):
            field.validate(MockConfig(), 'file.txt')

        exists.assert_called_once_with('file.txt')
예제 #2
0
 def test_empty_required(self):
     field = FilenameField(required=True, exists=True)
     with pytest.raises(ValueError):
         field.validate(MockConfig(), '')
예제 #3
0
 def test_empty_not_required(self):
     field = FilenameField(exists=True)
     assert field.validate(MockConfig(), '') == ''
예제 #4
0
 def test_file_false(self, isfile):
     isfile.return_value = False
     field = FilenameField(exists='file')
     with pytest.raises(ValueError):
         field.validate(MockConfig(), 'some-file')
     isfile.assert_called_once_with('some-file')
예제 #5
0
 def test_file_true(self, isfile):
     isfile.return_value = True
     field = FilenameField(exists='file')
     assert field.validate(MockConfig(), 'some-file') == 'some-file'
     isfile.assert_called_once_with('some-file')
예제 #6
0
 def test_dir_true(self, isdir):
     isdir.return_value = True
     field = FilenameField(exists='dir')
     assert field.validate(MockConfig(), 'some-dir') == 'some-dir'
     isdir.assert_called_once_with('some-dir')
예제 #7
0
 def test_exists_false_false(self, exists):
     exists.return_value = False
     field = FilenameField(exists=False)
     assert field.validate(MockConfig(), 'file.txt') == 'file.txt'
     exists.assert_called_once_with('file.txt')
예제 #8
0
 def test_convert_win_slashes(self):
     field = FilenameField()
     assert field.validate(MockConfig(), '/file.txt') == '\\file.txt'
예제 #9
0
 def test_absolute(self):
     field = FilenameField(startdir=os.getcwd())
     assert field.validate(MockConfig(), os.path.sep +
                           'file.txt') == os.path.sep + 'file.txt'
예제 #10
0
 def test_resolve_relative(self):
     field = FilenameField(startdir=os.getcwd())
     assert field.validate(MockConfig(), 'file.txt') == os.path.join(
         os.getcwd(), 'file.txt')