Skip to content

Commit c0b08b5

Browse files
committed
Format tests
1 parent 7b7915e commit c0b08b5

File tree

4 files changed

+716
-769
lines changed

4 files changed

+716
-769
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77
pull_request:
88
branches: [ "main", "master" ]
99
paths: [ 'src/**' ]
10-
11-
12-
jobs:
10+
11+
12+
jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest

test/FunctionalTests/ChatTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,27 @@ public class ChatTests
1818
[SetUp]
1919
public async Task Setup()
2020
{
21-
// Set up the test environment
2221
_client = new OllamaApiClient(_baseUri);
2322
_chat = new Chat(_client);
2423

2524
var modelExists = (await _client.ListLocalModelsAsync()).Any(m => m.Name == _model);
26-
2725
if (!modelExists)
2826
await _client.PullModelAsync(_model).ToListAsync();
2927
}
3028

3129
[TearDown]
3230
public Task Teardown()
3331
{
34-
// Clean up the test environment
3532
((IChatClient?)_client)?.Dispose();
36-
3733
return Task.CompletedTask;
3834
}
3935

4036

4137
[Test]
4238
public async Task SendAsync_ShouldSucceed()
4339
{
44-
// Arrange
4540
_client.SelectedModel = _model;
4641

47-
// Act
4842
var response = await _chat
4943
.SendAsync("What is the ultimate answer to " +
5044
"life, the universe, and everything, as specified in " +
@@ -53,7 +47,6 @@ public async Task SendAsync_ShouldSucceed()
5347
CancellationToken.None)
5448
.StreamToEndAsync();
5549

56-
// Assert
5750
response.Should().NotBeNullOrEmpty();
5851
response.Should().ContainAny("42", "forty-two", "forty two");
5952
}

test/FunctionalTests/OllamaApiClientTests.cs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,41 @@ public class OllamaApiClientTests
2222
[SetUp]
2323
public async Task Setup()
2424
{
25-
// Set up the test environment
2625
_client = new OllamaApiClient(_baseUri);
27-
2826
await CleanupModel(_localModel);
2927
}
3028

3129
[TearDown]
3230
public async Task Teardown()
3331
{
34-
// Clean up the test environment
3532
await CleanupModel(_localModel);
36-
3733
((IChatClient?)_client)?.Dispose();
3834
}
3935

4036
private async Task CleanupModel(string? model = null)
4137
{
42-
var modelExists = (await _client.ListLocalModelsAsync())
43-
.Any(m => m.Name == (model ?? _model));
38+
var modelExists = (await _client.ListLocalModelsAsync()).Any(m => m.Name == (model ?? _model));
4439

4540
if (modelExists)
4641
await _client.DeleteModelAsync(new DeleteModelRequest { Model = model ?? _model });
4742
}
4843

4944
private async Task PullIfNotExists(string model)
5045
{
51-
var modelExists = (await _client.ListLocalModelsAsync())
52-
.Any(m => m.Name == model);
46+
var modelExists = (await _client.ListLocalModelsAsync()).Any(m => m.Name == model);
5347

5448
if (!modelExists)
55-
await _client.PullModelAsync(new PullModelRequest { Model = model })
56-
.ToListAsync();
49+
await _client.PullModelAsync(new PullModelRequest { Model = model }).ToListAsync();
5750
}
5851

5952

60-
[Test, Category("Ft"), Order(1), Ignore("Prevent the model from being downloaded each test run")]
53+
[Test, Order(1), Ignore("Prevent the model from being downloaded each test run")]
6154
public async Task PullModel()
6255
{
63-
// Act
6456
var response = await _client
6557
.PullModelAsync(new PullModelRequest { Model = _model })
6658
.ToListAsync();
6759

68-
// Assert
6960
var models = await _client.ListLocalModelsAsync();
7061
models.Should().Contain(m => m.Name == _model);
7162

@@ -77,7 +68,6 @@ public async Task PullModel()
7768
[Test, Order(2)]
7869
public async Task CreateModel()
7970
{
80-
// Arrange
8171
await PullIfNotExists(_localModel);
8272

8373
var model = new CreateModelRequest
@@ -94,12 +84,10 @@ PARAMETER num_ctx 100
9484
"""
9585
};
9686

97-
// Act
9887
var response = await _client
9988
.CreateModelAsync(model)
10089
.ToListAsync();
10190

102-
// Assert
10391
var models = await _client.ListLocalModelsAsync();
10492
models.Should().Contain(m => m.Name.StartsWith(_localModel));
10593

@@ -110,34 +98,27 @@ PARAMETER num_ctx 100
11098
[Test, Order(3)]
11199
public async Task CopyModel()
112100
{
113-
// Arrange
114101
await PullIfNotExists(_localModel);
115102

116103
var model = new CopyModelRequest { Source = _localModel, Destination = $"{_localModel}-copy" };
117104

118-
// Act
119105
await _client.CopyModelAsync(model);
120106

121-
// Assert
122107
var models = await _client.ListLocalModelsAsync();
123108
models.Should().Contain(m => m.Name == $"{_localModel}-copy:latest");
124109

125-
// Clean up
126110
await _client.DeleteModelAsync(new DeleteModelRequest { Model = $"{_localModel}-copy:latest" });
127111
}
128112

129113
[Test]
130114
public async Task Embed()
131115
{
132-
// Arrange
133116
await PullIfNotExists(_embeddingModel);
134117

135118
var request = new EmbedRequest { Model = _embeddingModel, Input = ["Hello, world!"] };
136119

137-
// Act
138120
var response = await _client.EmbedAsync(request);
139121

140-
// Assert
141122
response.Should().NotBeNull();
142123
response.Embeddings.Should().NotBeEmpty();
143124
response.LoadDuration.Should().BeGreaterThan(100, "Because loading the model should take some time");
@@ -147,18 +128,15 @@ public async Task Embed()
147128
[Test]
148129
public async Task ListLocalModels()
149130
{
150-
// Act
151131
var models = (await _client.ListLocalModelsAsync()).ToList();
152132

153-
// Assert
154133
models.Should().NotBeEmpty();
155134
models.Should().Contain(m => m.Name == _model);
156135
}
157136

158137
[Test]
159138
public async Task ListRunningModels()
160139
{
161-
// Arrange
162140
await PullIfNotExists(_model);
163141
var backgroundTask = Task.Run(async () =>
164142
{
@@ -171,28 +149,21 @@ public async Task ListRunningModels()
171149
await generate;
172150
});
173151

174-
// Act
175152
var modelsTask = _client.ListRunningModelsAsync();
176-
177153
await Task.WhenAll(backgroundTask, modelsTask);
178154

179-
// Assert
180155
var models = modelsTask.Result.ToList();
181-
182156
models.Should().NotBeEmpty();
183157
models.Should().Contain(m => m.Name == _model);
184158
}
185159

186160
[Test]
187161
public async Task ShowModel()
188162
{
189-
// Arrange
190163
await PullIfNotExists(_model);
191164

192-
// Act
193165
var response = await _client.ShowModelAsync(new ShowModelRequest { Model = _model });
194166

195-
// Assert
196167
response.Should().NotBeNull();
197168
response.Info.Should().NotBeNull();
198169
response.Info.Architecture.Should().Be("llama");
@@ -204,34 +175,28 @@ public async Task ShowModel()
204175
[Test]
205176
public async Task DeleteModel()
206177
{
207-
// Arrange
208178
await PullIfNotExists(_localModel);
209179
await _client.CopyModelAsync(new CopyModelRequest
210180
{
211181
Source = _localModel,
212182
Destination = $"{_localModel}-copy"
213183
});
214184

215-
var exists = (await _client.ListLocalModelsAsync())
216-
.Any(m => m.Name == $"{_localModel}-copy:latest");
185+
var exists = (await _client.ListLocalModelsAsync()).Any(m => m.Name == $"{_localModel}-copy:latest");
217186

218187
exists.Should().BeTrue();
219188

220-
// Act
221189
await _client.DeleteModelAsync(new DeleteModelRequest { Model = $"{_localModel}-copy:latest" });
222190

223-
// Assert
224191
var models = await _client.ListLocalModelsAsync();
225192
models.Should().NotContain(m => m.Name == $"{_localModel}-copy:latest");
226193
}
227194

228195
[Test]
229196
public async Task GenerateAsync()
230197
{
231-
// Arrange
232198
await PullIfNotExists(_model);
233199

234-
// Act
235200
var response = await _client.GenerateAsync(new GenerateRequest
236201
{
237202
Model = _model,
@@ -242,18 +207,15 @@ public async Task GenerateAsync()
242207

243208
var joined = string.Join("", response.Select(r => r.Response));
244209

245-
// Assert
246210
response.Should().NotBeEmpty();
247211
joined.Should().Contain("42");
248212
}
249213

250214
[Test]
251215
public async Task ChatAsync()
252216
{
253-
// Arrange
254217
await PullIfNotExists(_model);
255218

256-
// Act
257219
var response = await _client.ChatAsync(new ChatRequest
258220
{
259221
Model = _model,
@@ -280,28 +242,21 @@ public async Task ChatAsync()
280242

281243
var joined = string.Join("", response.Select(r => r.Message.Content));
282244

283-
// Assert
284245
response.Should().NotBeEmpty();
285246
joined.Should().Contain("Douglas Adams");
286247
}
287248

288249
[Test]
289250
public async Task IsRunningAsync()
290251
{
291-
// Act
292252
var response = await _client.IsRunningAsync();
293-
294-
// Assert
295253
response.Should().BeTrue();
296254
}
297255

298256
[Test]
299257
public async Task GetVersionAsync()
300258
{
301-
// Act
302259
var response = await _client.GetVersionAsync();
303-
304-
// Assert
305260
response.Should().NotBeNull();
306261
}
307262
}

0 commit comments

Comments
 (0)