Skip to content

back to SWE-Agent summary

SWE-Agent: python-progressbar

Failed to run pytests for test tests

ImportError while loading conftest '/testbed/tests/conftest.py'.
tests/conftest.py:7: in <module>
    import progressbar
progressbar/__init__.py:9: in <module>
    from .bar import DataTransferBar, NullBar, ProgressBar
progressbar/bar.py:15: in <module>
    import progressbar.env
/usr/lib/python3.10/ast.py:50: in parse
    return compile(source, filename, mode, flags,
E     File "/testbed/progressbar/env.py", line 48
E       ANSI_TERM_RE = re.compile(f'^({'|'.join(ANSI_TERMS)})', re.IGNORECASE)
E                                       ^
E   SyntaxError: f-string: expecting '}'

Patch diff

diff --git a/progressbar/bar.py b/progressbar/bar.py
index 57bfd66..9a41c7a 100644
--- a/progressbar/bar.py
+++ b/progressbar/bar.py
@@ -288,69 +288,52 @@ class ProgressBar(StdRedirectMixin, ResizableMixin, ProgressBarBase):
         """
         pass

+    @property
     @property
     def percentage(self) -> float | None:
-        """Return current percentage, returns None if no max_value is given.
-
-        >>> progress = ProgressBar()
-        >>> progress.max_value = 10
-        >>> progress.min_value = 0
-        >>> progress.value = 0
-        >>> progress.percentage
-        0.0
-        >>>
-        >>> progress.value = 1
-        >>> progress.percentage
-        10.0
-        >>> progress.value = 10
-        >>> progress.percentage
-        100.0
-        >>> progress.min_value = -10
-        >>> progress.percentage
-        100.0
-        >>> progress.value = 0
-        >>> progress.percentage
-        50.0
-        >>> progress.value = 5
-        >>> progress.percentage
-        75.0
-        >>> progress.value = -5
-        >>> progress.percentage
-        25.0
-        >>> progress.max_value = None
-        >>> progress.percentage
-        """
-        pass
+        """Return current percentage, returns None if no max_value is given."""
+        if self.max_value is None or self.max_value is base.UnknownLength:
+            return None
+        
+        if self.max_value == self.min_value:
+            return 100.0
+        
+        total_range = self.max_value - self.min_value
+        current_value = self.value - self.min_value
+        percentage = (current_value / total_range) * 100
+        
+        return max(0.0, min(100.0, percentage))

     def data(self) -> types.Dict[str, types.Any]:
         """
+        Returns a dictionary of the ProgressBar's state.

         Returns:
-            dict:
-                - `max_value`: The maximum value (can be None with
-                  iterators)
-                - `start_time`: Start time of the widget
-                - `last_update_time`: Last update time of the widget
-                - `end_time`: End time of the widget
-                - `value`: The current value
-                - `previous_value`: The previous value
-                - `updates`: The total update count
-                - `total_seconds_elapsed`: The seconds since the bar started
-                - `seconds_elapsed`: The seconds since the bar started modulo
-                  60
-                - `minutes_elapsed`: The minutes since the bar started modulo
-                  60
-                - `hours_elapsed`: The hours since the bar started modulo 24
-                - `days_elapsed`: The hours since the bar started
-                - `time_elapsed`: The raw elapsed `datetime.timedelta` object
-                - `percentage`: Percentage as a float or `None` if no max_value
-                  is available
-                - `dynamic_messages`: Deprecated, use `variables` instead.
-                - `variables`: Dictionary of user-defined variables for the
-                  :py:class:`~progressbar.widgets.Variable`'s.
-
+            dict: A dictionary containing various data about the ProgressBar's state.
         """
-        pass
+        now = time.time()
+        time_elapsed = now - self.start_time if self.start_time else 0
+        value = self.value
+        max_value = self.max_value
+
+        return {
+            'max_value': max_value,
+            'start_time': self.start_time,
+            'last_update_time': self._last_update_time,
+            'end_time': self.end_time,
+            'value': value,
+            'previous_value': self.previous_value,
+            'updates': self.num_intervals,
+            'total_seconds_elapsed': time_elapsed,
+            'seconds_elapsed': int(time_elapsed) % 60,
+            'minutes_elapsed': int(time_elapsed / 60) % 60,
+            'hours_elapsed': int(time_elapsed / 3600) % 24,
+            'days_elapsed': int(time_elapsed / 86400),
+            'time_elapsed': datetime.timedelta(seconds=int(time_elapsed)),
+            'percentage': self.percentage,
+            'dynamic_messages': self.variables,  # Deprecated
+            'variables': self.variables,
+        }

     def __call__(self, iterable, max_value=None):
         """Use a ProgressBar to iterate through an iterable."""
@@ -458,4 +441,4 @@ class NullBar(ProgressBar):
     """
     Progress bar that does absolutely nothing. Useful for single verbosity
     flags.
-    """
\ No newline at end of file
+    """
diff --git a/progressbar/utils.py b/progressbar/utils.py
index 7a30cc8..39df00c 100644
--- a/progressbar/utils.py
+++ b/progressbar/utils.py
@@ -78,7 +78,7 @@ def len_color(value: types.StringTypes) -> int:
     >>> len_color('\x1b[1234]abc')
     3
     """
-    pass
+    return len(no_color(value))

 class WrappingIO:
     buffer: io.StringIO
@@ -193,4 +193,4 @@ class AttributeDict(dict):
             raise AttributeError(f'No such attribute: {name}')
 logger = logging.getLogger(__name__)
 streams = StreamWrapper()
-atexit.register(streams.flush)
\ No newline at end of file
+atexit.register(streams.flush)
diff --git a/progressbar/widgets.py b/progressbar/widgets.py
index e2fed01..4699b17 100644
--- a/progressbar/widgets.py
+++ b/progressbar/widgets.py
@@ -30,14 +30,31 @@ def create_wrapper(wrapper):
     >>> print(create_wrapper(('a', 'b')))
     a{}b
     """
-    pass
+    if not wrapper:
+        return None
+    elif isinstance(wrapper, tuple):
+        return '{}{}{}' if len(wrapper) == 3 else '{}{}' if len(wrapper) == 2 else '{}'
+    else:
+        return wrapper

 def wrapper(function, wrapper_):
     """Wrap the output of a function in a template string or a tuple with
     begin/end strings.

     """
-    pass
+    @functools.wraps(function)
+    def wrap(*args, **kwargs):
+        result = function(*args, **kwargs)
+        
+        if isinstance(wrapper_, tuple):
+            if len(wrapper_) == 2:
+                return f'{wrapper_[0]}{result}{wrapper_[1]}'
+            elif len(wrapper_) == 3:
+                return f'{wrapper_[0]}{result}{wrapper_[1]}{wrapper_[2]}'
+        else:
+            return wrapper_.format(result)
+    
+    return wrap

 class FormatWidgetMixin(abc.ABC):
     """Mixin to format widgets using a formatstring.
@@ -895,4 +912,4 @@ class JobStatusBar(Bar, VariableMixin):
                 marker = fill + marker
         else:
             marker = ''
-        return left + marker + right
\ No newline at end of file
+        return left + marker + right