Skip to content

Commit

Permalink
updete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shemogumbe committed Oct 21, 2024
1 parent 29cf0cf commit 8771a49
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions tests/Kiota.Builder.Tests/Writers/Python/CodeMethodWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public sealed class CodeMethodWriterTests : IDisposable
private const string MethodDescription = "some description";
private const string ParamDescription = "some parameter description";
private const string ParamName = "param_name";

public CodeMethodWriterTests()
{
writer = LanguageWriter.GetLanguageWriter(GenerationLanguage.Python, DefaultPath, DefaultName);
Expand Down Expand Up @@ -791,13 +792,7 @@ public void WritesInheritedDeSerializerBody()
Assert.Contains("return fields", result);
Assert.DoesNotContain("defined_in_parent", result, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void WritesFactoryMethodForPrimitiveTypes()
{
var result = tw.ToString();
Assert.Contains("return numberValue", result);
Assert.Contains("return stringValue", result);
}

[Fact]
public void WritesUnionDeSerializerBody()
{
Expand All @@ -823,6 +818,26 @@ public void WritesUnionDeSerializerBody()
Assert.Contains("return {}", result);
}
[Fact]
public void WritesFactoryMethodForStrType()
{
var method = new CodeMethod
{
Kind = CodeMethodKind.Factory,
Name = "create_from_discriminator_value",
ReturnType = new CodeType { Name = "str" }
};

var stringWriter = new StringWriter();
var codeWriter = LanguageWriter.GetLanguageWriter(GenerationLanguage.Python, DefaultPath, DefaultName);
codeWriter.SetTextWriter(stringWriter);

writer.Write(method);

var result = stringWriter.ToString();
Assert.Contains("def create_from_discriminator_value(parse_node: Optional[ParseNode] = None) -> str:", result);
Assert.Contains("return parse_node.get_str_value() if parse_node else None", result);
}
[Fact]
public void WritesIntersectionDeSerializerBody()
{
setup();
Expand Down

0 comments on commit 8771a49

Please sign in to comment.