Skip to content

Enable doc tests with new test infra #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions tests/Doc/Bf_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Bf_tutorial
public class Bf_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Bf_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern is that the user can see this part of the code when they view the whole file (eg, if you go here and click the little eye widget on any code tab).

It looks like some of this isn't code that we can recommend to users as part of the example. We can filter out [SkippableTheory] and the other attributes when we pull the example into the docs. We might also be able to remove the inherited test classes, etc. However, I'm not sure about the GetCleanDatabase(). If this is the best/only way to handle the tests, then we might have to add something to the docs processing, a bit like:

// REMOVE_START
var db = GetCleanDatabase(endpointId); // <-- Code that actually gets tested.
// REMOVE_END
/* ADD_START <-- New processing command
var muxer = ConnectionMultiplexer.Connect("localhost:6379"); <-- Code the user sees.
var db = muxer.GetDatabase();
ADD_END */

I guess I could implement this fairly easily in the Python script that processes the docs, but it would mean that the code the user sees isn't exactly the same as the code that gets tested in the NRedisStack repo. Maybe that wouldn't be a problem since most of the real code is the same?

I'm not sure about the best way to handle this, but there are probably other options. Aside from this, it's great to see improvements to the docs testing :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andy-stark-redis i am at the same spot with you on your concern.
i guess i just jumped in to enable doc tests with new infra but looks like it was too quick to catch what you've shown.
running and displaying different code is not the ideal, i believe.
then how do we handle it in other client libs? let me see.

//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("bikes:models");
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/Bitmap_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Bitmap_tutorial
public class Bitmap_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Bitmap_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("pings:2024-01-01-00:00");
Expand Down
12 changes: 8 additions & 4 deletions tests/Doc/CmdsGenericExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class CmdsGenericExample
public class CmdsGenericExample : AbstractNRedisStackTest, IDisposable
{
public CmdsGenericExample(EndpointsFixture fixture) : base(fixture) { }

public void run()

[SkipIfRedis(Comparison.LessThan, "7.0.0")]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]

public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.

Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/CmdsHashExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class CmdsHashExample
public class CmdsHashExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public CmdsHashExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("myhash");
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/CmdsSortedSetExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class CmdsSortedSet
public class CmdsSortedSet: AbstractNRedisStackTest, IDisposable
{

public void run()
public CmdsSortedSet(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.

Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/CmdsStringExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class CmdsStringExample
public class CmdsStringExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public CmdsStringExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.

Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/Cms_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Cms_tutorial
public class Cms_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Cms_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("bikes:profit");
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/Cuckoo_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Cuckoo_tutorial
public class Cuckoo_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Cuckoo_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("bikes:models");
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/Geo_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Geo_tutorial
public class Geo_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Geo_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("bikes:rentable");
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/HashExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
namespace Doc;
[Collection("DocsTests")]
//REMOVE_END
public class HashExample
public class HashExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public HashExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
db.KeyDelete("bike:1");
//HIDE_END
//STEP_START set_get_all
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/Hll_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Hll_tutorial
public class Hll_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Hll_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete(new RedisKey[] { "{bikes}", "commuter_{bikes}", "all_{bikes}" });
Expand Down
13 changes: 8 additions & 5 deletions tests/Doc/HomeJsonExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class HomeJsonExample
public class HomeJsonExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public HomeJsonExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
// STEP_START connect
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();

var db = GetCleanDatabase(endpointId);
// STEP_END

//REMOVE_START
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/Json_tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class Json_tutorial
public class Json_tutorial : AbstractNRedisStackTest, IDisposable
{

public void run()
public Json_tutorial(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
db.KeyDelete("bike");
Expand Down
13 changes: 9 additions & 4 deletions tests/Doc/ListTutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
namespace Doc;
[Collection("DocsTests")]
//REMOVE_END
public class ListExample
public class ListExample: AbstractNRedisStackTest, IDisposable
{
public void run()
public ListExample(EndpointsFixture fixture) : base(fixture) { }

//REMOVE_START
[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
//REMOVE_END
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//HIDE_END
//REMOVE_START
db.KeyDelete("bikes:repairs");
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/QueryAggExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class QueryAggExample
public class QueryAggExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public QueryAggExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
try { db.FT().DropIndex("idx:bicycle"); } catch { }
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/QueryEmExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class QueryEmExample
public class QueryEmExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public QueryEmExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
try { db.FT().DropIndex("idx:bicycle"); } catch { }
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/QueryFtExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class QueryFtExample
public class QueryFtExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public QueryFtExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
try { db.FT().DropIndex("idx:bicycle", true); } catch { }
Expand Down
12 changes: 7 additions & 5 deletions tests/Doc/QueryRangeExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace Doc;
// REMOVE_END

// HIDE_START
public class QueryRangeExample
public class QueryRangeExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public QueryRangeExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
var db = GetCleanDatabase(endpointId);
//REMOVE_START
// Clear any keys here before using them in tests.
try { db.FT().DropIndex("idx:bicycle", dd: true); } catch { }
Expand Down
9 changes: 6 additions & 3 deletions tests/Doc/SearchQuickstartExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
namespace Doc;
[Collection("DocsTests")]
// REMOVE_END
public class SearchQuickstartExample
public class SearchQuickstartExample: AbstractNRedisStackTest, IDisposable
{

public void run()
public SearchQuickstartExample(EndpointsFixture fixture) : base(fixture) { }

[SkippableTheory]
[MemberData(nameof(EndpointsFixture.Env.StandaloneOnly), MemberType = typeof(EndpointsFixture.Env))]
public void run(string endpointId)
{
// STEP_START connect
var redis = ConnectionMultiplexer.Connect("localhost:6379");
Expand Down
Loading
Loading