Skip to content

Attempt to get test file(s) from <indir>/.meta/config.json #50

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 4 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from copy import deepcopy
from typing import Dict, List, Optional
from pathlib import Path
import json

import pytest

Expand Down Expand Up @@ -143,10 +144,18 @@ def run(slug: Slug, indir: Directory, outdir: Directory, args: List[str]) -> Non
"""
Run the tests for the given exercise and produce a results.json.
"""
test_file = indir.joinpath(slug.replace("-", "_") + "_test.py")
test_files = []
config_file = indir.joinpath(".meta").joinpath("config.json")
if config_file.is_file():
config_data = json.loads(config_file.read_text())
editor_config = config_data.get("editor", {})
for filename in editor_config.get("test_files", []):
test_files.append(indir.joinpath(filename))
if not test_files:
test_files.append(indir.joinpath(slug.replace("-", "_") + "_test.py"))
out_file = outdir.joinpath("results.json")
# run the tests and report
reporter = ResultsReporter()
pytest.main(_sanitize_args(args or []) + [str(test_file)], plugins=[reporter])
pytest.main(_sanitize_args(args or []) + [str(tf) for tf in test_files], plugins=[reporter])
# dump the report
out_file.write_text(reporter.results.as_json())
5 changes: 5 additions & 0 deletions test/example-with-config-multiple-files/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor": {
"test_files": ["example_first_test.py", "example_second_test.py"]
}
}
24 changes: 24 additions & 0 deletions test/example-with-config-multiple-files/example_first_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest


from example_with_config import hello


class ExampleFirstTest(unittest.TestCase):
def test_hello(self):
self.assertEqual(hello(), "Hello, World!")

def test_abc(self):
self.assertEqual(hello(), "Hello, World!")


class ExampleFirstOtherTest(unittest.TestCase):
def test_dummy(self):
self.assertEqual(hello(), "Hello, World!")

def test_hello(self):
self.assertEqual(hello(), "Hello, World!")


if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions test/example-with-config-multiple-files/example_second_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest


from example_with_config import hello


class ExampleSecondTest(unittest.TestCase):
def test_hello(self):
self.assertEqual(hello(), "Hello, World!")

def test_abc(self):
self.assertEqual(hello(), "Hello, World!")


class ExampleSecondOtherTest(unittest.TestCase):
def test_dummy(self):
self.assertEqual(hello(), "Hello, World!")

def test_hello(self):
self.assertEqual(hello(), "Hello, World!")


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Example Exercism/Python solution file"""


def hello():
print("User output is captured!")
return "Hello, World!"
45 changes: 45 additions & 0 deletions test/example-with-config-multiple-files/results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"status": "pass",
"tests": [
{
"name": "ExampleFirstTest.test_hello",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleSecondTest.test_hello",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleFirstTest.test_abc",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleSecondTest.test_abc",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleFirstOtherTest.test_dummy",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleSecondOtherTest.test_dummy",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleFirstOtherTest.test_hello",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleSecondOtherTest.test_hello",
"status": "pass",
"output": "User output is captured!"
}
]
}
5 changes: 5 additions & 0 deletions test/example-with-config/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor": {
"test_files": ["example_with_config_test.py"]
}
}
6 changes: 6 additions & 0 deletions test/example-with-config/example_with_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Example Exercism/Python solution file"""


def hello():
print("User output is captured!")
return "Hello, World!"
24 changes: 24 additions & 0 deletions test/example-with-config/example_with_config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest


from example_with_config import hello


class ExampleWithConfigTest(unittest.TestCase):
def test_hello(self):
self.assertEqual(hello(), "Hello, World!")

def test_abc(self):
self.assertEqual(hello(), "Hello, World!")


class ExampleWithConfigOtherTest(unittest.TestCase):
def test_dummy(self):
self.assertEqual(hello(), "Hello, World!")

def test_hello(self):
self.assertEqual(hello(), "Hello, World!")


if __name__ == "__main__":
unittest.main()
25 changes: 25 additions & 0 deletions test/example-with-config/results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"status": "pass",
"tests": [
{
"name": "ExampleWithConfigTest.test_hello",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleWithConfigTest.test_abc",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleWithConfigOtherTest.test_dummy",
"status": "pass",
"output": "User output is captured!"
},
{
"name": "ExampleWithConfigOtherTest.test_hello",
"status": "pass",
"output": "User output is captured!"
}
]
}