コード例 #1
0
ファイル: test_downloads.py プロジェクト: likesea/httpie
    def test_unique_filename(self):
        def attempts(unique_on_attempt=0):
            # noinspection PyUnresolvedReferences,PyUnusedLocal
            def exists(filename):
                if exists.attempt == unique_on_attempt:
                    return False
                exists.attempt += 1
                return True

            exists.attempt = 0
            return exists

        assert 'foo.bar' == get_unique_filename('foo.bar', attempts(0))
        assert 'foo.bar-1' == get_unique_filename('foo.bar', attempts(1))
        assert 'foo.bar-10' == get_unique_filename('foo.bar', attempts(10))
コード例 #2
0
ファイル: test_downloads.py プロジェクト: 0xcc/httpie
    def test_unique_filename(self):
        def attempts(unique_on_attempt=0):
            # noinspection PyUnresolvedReferences,PyUnusedLocal
            def exists(filename):
                if exists.attempt == unique_on_attempt:
                    return False
                exists.attempt += 1
                return True

            exists.attempt = 0
            return exists

        assert 'foo.bar' == get_unique_filename('foo.bar', attempts(0))
        assert 'foo.bar-1' == get_unique_filename('foo.bar', attempts(1))
        assert 'foo.bar-10' == get_unique_filename('foo.bar', attempts(10))
コード例 #3
0
    def test_unique_filename(self):
        def make_exists(unique_on_attempt=0):
            # noinspection PyUnresolvedReferences,PyUnusedLocal
            def exists(filename):
                if exists.attempt == unique_on_attempt:
                    return False
                exists.attempt += 1
                return True

            exists.attempt = 0
            return exists

        self.assertEqual(get_unique_filename('foo.bar', exists=make_exists()),
                         'foo.bar')
        self.assertEqual(get_unique_filename('foo.bar', exists=make_exists(1)),
                         'foo.bar-1')
        self.assertEqual(
            get_unique_filename('foo.bar', exists=make_exists(10)),
            'foo.bar-10')
コード例 #4
0
ファイル: tests.py プロジェクト: Elarnon/httpie
    def test_unique_filename(self):

        def make_exists(unique_on_attempt=0):
            # noinspection PyUnresolvedReferences,PyUnusedLocal
            def exists(filename):
                if exists.attempt == unique_on_attempt:
                    return False
                exists.attempt += 1
                return True
            exists.attempt = 0
            return exists

        self.assertEqual(
            get_unique_filename('foo.bar', exists=make_exists()),
            'foo.bar'
        )
        self.assertEqual(
            get_unique_filename('foo.bar', exists=make_exists(1)),
            'foo.bar-1'
        )
        self.assertEqual(
            get_unique_filename('foo.bar', exists=make_exists(10)),
            'foo.bar-10'
        )
コード例 #5
0
ファイル: test_downloads.py プロジェクト: yinwin/httpie
    def test_unique_filename(self, get_filename_max_length, orig_name,
                             unique_on_attempt, expected):
        def attempts(unique_on_attempt=0):
            # noinspection PyUnresolvedReferences,PyUnusedLocal
            def exists(filename):
                if exists.attempt == unique_on_attempt:
                    return False
                exists.attempt += 1
                return True

            exists.attempt = 0
            return exists

        get_filename_max_length.return_value = 10

        actual = get_unique_filename(orig_name, attempts(unique_on_attempt))
        assert expected == actual
コード例 #6
0
    def test_unique_filename(self, get_filename_max_length,
                             orig_name, unique_on_attempt,
                             expected):

        def attempts(unique_on_attempt=0):
            # noinspection PyUnresolvedReferences,PyUnusedLocal
            def exists(filename):
                if exists.attempt == unique_on_attempt:
                    return False
                exists.attempt += 1
                return True

            exists.attempt = 0
            return exists

        get_filename_max_length.return_value = 10

        actual = get_unique_filename(orig_name, attempts(unique_on_attempt))
        assert expected == actual