Skip to content

Commit 76857c0

Browse files
committed
Add formatting and linting for C# files
1 parent 563e369 commit 76857c0

File tree

117 files changed

+929
-752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+929
-752
lines changed

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
lint-dotnet:
11+
name: Lint .NET
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v1
21+
with:
22+
dotnet-version: '7.0.x'
23+
24+
- name: Lint
25+
run: dotnet format -v diag --verify-no-changes --report=format.json
26+
27+
- uses: actions/upload-artifact@v4
28+
with:
29+
name: format-report
30+
path: format.json

src/console/pythonconsole.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Reflection;
5+
56
using Python.Runtime;
67

78
namespace Python.Runtime

src/embed_tests/CodecGroups.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ namespace Python.EmbeddingTest
22
{
33
using System;
44
using System.Linq;
5+
56
using NUnit.Framework;
7+
68
using Python.Runtime;
79
using Python.Runtime.Codecs;
810

@@ -20,7 +22,7 @@ public void GetEncodersByType()
2022
};
2123

2224
var got = group.GetEncoders(typeof(Uri)).ToArray();
23-
CollectionAssert.AreEqual(new[]{encoder1, encoder2}, got);
25+
CollectionAssert.AreEqual(new[] { encoder1, encoder2 }, got);
2426
}
2527

2628
[Test]

src/embed_tests/Codecs.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
namespace Python.EmbeddingTest {
1+
namespace Python.EmbeddingTest
2+
{
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
6+
57
using NUnit.Framework;
8+
69
using Python.Runtime;
710
using Python.Runtime.Codecs;
811

@@ -169,7 +172,8 @@ public void SequenceDecoderTest()
169172
ICollection<string> stringCollection = null;
170173
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringCollection); });
171174
Assert.AreEqual(3, stringCollection.Count());
172-
Assert.Throws(typeof(InvalidCastException), () => {
175+
Assert.Throws(typeof(InvalidCastException), () =>
176+
{
173177
string[] array = new string[3];
174178
stringCollection.CopyTo(array, 0);
175179
});
@@ -206,7 +210,8 @@ public void SequenceDecoderTest()
206210
ICollection<string> stringCollection2 = null;
207211
Assert.DoesNotThrow(() => { codec.TryDecode(pyTuple, out stringCollection2); });
208212
Assert.AreEqual(3, stringCollection2.Count());
209-
Assert.Throws(typeof(InvalidCastException), () => {
213+
Assert.Throws(typeof(InvalidCastException), () =>
214+
{
210215
string[] array = new string[3];
211216
stringCollection2.CopyTo(array, 0);
212217
});
@@ -255,13 +260,15 @@ public void IterableDecoderTest()
255260
IEnumerable<string> stringEnumerable = null;
256261
Assert.DoesNotThrow(() => { codec.TryDecode(pyList, out stringEnumerable); });
257262

258-
Assert.Throws(typeof(InvalidCastException), () => {
263+
Assert.Throws(typeof(InvalidCastException), () =>
264+
{
259265
foreach (string item in stringEnumerable)
260266
{
261267
var x = item;
262268
}
263269
});
264-
Assert.Throws(typeof(InvalidCastException), () => {
270+
Assert.Throws(typeof(InvalidCastException), () =>
271+
{
265272
stringEnumerable.Count();
266273
});
267274

@@ -390,7 +397,7 @@ public void ExceptionDecodedNoInstance()
390397
}
391398
}
392399

393-
public static void AcceptsDateTime(DateTime v) {}
400+
public static void AcceptsDateTime(DateTime v) { }
394401

395402
[Test]
396403
public void As_Object_AffectedByDecoders()

src/embed_tests/GlobalTestsSetup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
23
using Python.Runtime;
34

45
namespace Python.EmbeddingTest

src/embed_tests/Inheritance.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public class PropertyAccessorBase
206206
public virtual string VirtualProp { get; set; }
207207
}
208208

209-
public class PropertyAccessorIntermediate: PropertyAccessorBase { }
209+
public class PropertyAccessorIntermediate : PropertyAccessorBase { }
210210

211-
public class PropertyAccessorDerived: PropertyAccessorIntermediate
211+
public class PropertyAccessorDerived : PropertyAccessorIntermediate
212212
{
213213
public override string VirtualProp { set => base.VirtualProp = value.ToUpperInvariant(); }
214214
}
@@ -217,7 +217,7 @@ public class ContainerClass
217217
{
218218
public void BaseMethod() { }
219219

220-
public class InnerClass: ContainerClass
220+
public class InnerClass : ContainerClass
221221
{
222222

223223
}

src/embed_tests/Modules.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Threading;
3+
34
using NUnit.Framework;
5+
46
using Python.Runtime;
57

68
namespace Python.EmbeddingTest
@@ -385,8 +387,8 @@ public void TestThread()
385387
//add function to the scope
386388
//can be call many times, more efficient than ast
387389
ps.Exec(
388-
"import threading\n"+
389-
"lock = threading.Lock()\n"+
390+
"import threading\n" +
391+
"lock = threading.Lock()\n" +
390392
"def update():\n" +
391393
" global res, th_cnt\n" +
392394
" with lock:\n" +

src/embed_tests/NumPyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void VarArg()
6868
{
6969
dynamic zX = np.array(new[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 8, 9, 0 } });
7070
dynamic grad = np.gradient(zX, 4.0, 5.0);
71-
dynamic grad2 = np.InvokeMethod("gradient", new PyObject[] {zX, new PyFloat(4.0), new PyFloat(5.0)});
71+
dynamic grad2 = np.InvokeMethod("gradient", new PyObject[] { zX, new PyFloat(4.0), new PyFloat(5.0) });
7272

7373
Assert.AreEqual(4.125, grad[0].sum().__float__().As<double>(), 0.001);
7474
Assert.AreEqual(-1.2, grad[1].sum().__float__().As<double>(), 0.001);

src/embed_tests/References.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Python.EmbeddingTest
22
{
33
using NUnit.Framework;
4+
45
using Python.Runtime;
56

67
public class References

src/embed_tests/TestCallbacks.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
using System;
22

33
using NUnit.Framework;
4+
45
using Python.Runtime;
56

6-
namespace Python.EmbeddingTest {
7-
public class TestCallbacks {
7+
namespace Python.EmbeddingTest
8+
{
9+
public class TestCallbacks
10+
{
811
[OneTimeSetUp]
9-
public void SetUp() {
12+
public void SetUp()
13+
{
1014
PythonEngine.Initialize();
1115
}
1216

1317
[OneTimeTearDown]
14-
public void Dispose() {
18+
public void Dispose()
19+
{
1520
PythonEngine.Shutdown();
1621
}
1722

1823
[Test]
19-
public void TestNoOverloadException() {
24+
public void TestNoOverloadException()
25+
{
2026
int passed = 0;
2127
var aFunctionThatCallsIntoPython = new Action<int>(value => passed = value);
22-
using (Py.GIL()) {
28+
using (Py.GIL())
29+
{
2330
using dynamic callWith42 = PythonEngine.Eval("lambda f: f([42])");
2431
using var pyFunc = aFunctionThatCallsIntoPython.ToPython();
25-
var error = Assert.Throws<PythonException>(() => callWith42(pyFunc));
32+
var error = Assert.Throws<PythonException>(() => callWith42(pyFunc));
2633
Assert.AreEqual("TypeError", error.Type.Name);
2734
string expectedArgTypes = "(<class 'list'>)";
2835
StringAssert.EndsWith(expectedArgTypes, error.Message);

0 commit comments

Comments
 (0)