add ForceAutoRefresh opt to tests that were relying on auto refresh
Vladimir Bauer
3 years ago
| 117 | 117 | |
| 118 | 118 | func TestBarSetRefill(t *testing.T) { |
| 119 | 119 | var buf bytes.Buffer |
| 120 | ||
| 121 | p := mpb.New(mpb.WithOutput(&buf), mpb.WithWidth(100)) | |
| 120 | p := mpb.New( | |
| 121 | mpb.WithWidth(100), | |
| 122 | mpb.WithOutput(&buf), | |
| 123 | mpb.ForceAutoRefresh(), | |
| 124 | ) | |
| 122 | 125 | |
| 123 | 126 | total := 100 |
| 124 | 127 | till := 30 |
| 146 | 149 | |
| 147 | 150 | func TestBarHas100PercentWithBarRemoveOnComplete(t *testing.T) { |
| 148 | 151 | var buf bytes.Buffer |
| 149 | ||
| 150 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(&buf)) | |
| 152 | p := mpb.New( | |
| 153 | mpb.WithWidth(80), | |
| 154 | mpb.WithOutput(&buf), | |
| 155 | mpb.ForceAutoRefresh(), | |
| 156 | ) | |
| 151 | 157 | |
| 152 | 158 | total := 50 |
| 153 | 159 | |
| 171 | 177 | customFormat := "╢▌▌░╟" |
| 172 | 178 | runes := []rune(customFormat) |
| 173 | 179 | total := 80 |
| 174 | p := mpb.New(mpb.WithWidth(total), mpb.WithOutput(&buf)) | |
| 180 | p := mpb.New( | |
| 181 | mpb.WithWidth(80), | |
| 182 | mpb.WithOutput(&buf), | |
| 183 | mpb.ForceAutoRefresh(), | |
| 184 | ) | |
| 175 | 185 | bs := mpb.BarStyle() |
| 176 | 186 | bs.Lbound(string(runes[0])) |
| 177 | 187 | bs.Filler(string(runes[1])) |
| 246 | 256 | ctx, cancel := context.WithCancel(context.Background()) |
| 247 | 257 | p := mpb.NewWithContext(ctx, |
| 248 | 258 | mpb.WithOutput(io.Discard), |
| 259 | mpb.ForceAutoRefresh(), | |
| 249 | 260 | mpb.WithShutdownNotifier(shutdown), |
| 250 | 261 | ) |
| 251 | b := p.AddBar(100) | |
| 252 | q := p.AddBar(100, mpb.BarQueueAfter(b)) | |
| 253 | ||
| 254 | b.IncrBy(100) | |
| 255 | b.Wait() | |
| 262 | a := p.AddBar(100) | |
| 263 | b := p.AddBar(100, mpb.BarQueueAfter(a)) | |
| 264 | identity := map[*mpb.Bar]string{ | |
| 265 | a: "a", | |
| 266 | b: "b", | |
| 267 | } | |
| 268 | ||
| 269 | a.IncrBy(100) | |
| 270 | a.Wait() | |
| 256 | 271 | cancel() |
| 257 | 272 | |
| 258 | 273 | bars := (<-shutdown).([]*mpb.Bar) |
| 261 | 276 | } |
| 262 | 277 | |
| 263 | 278 | p.Wait() |
| 264 | if bars[0] != q { | |
| 265 | t.Errorf("Expected bars[0]: %p, got: %p", q, bars[0]) | |
| 266 | } | |
| 267 | } | |
| 279 | if bars[0] != b { | |
| 280 | t.Errorf("Expected bars[0] == b, got: %s", identity[bars[0]]) | |
| 281 | } | |
| 282 | } | |