Skip to content

Commit

Permalink
default in lab50 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelleas committed Jun 14, 2019
1 parent 03d76c7 commit 7356e65
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/lib50_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,42 +431,44 @@ def test_non_file_require(self):
included, excluded = lib50.files(config.get("files"))

def test_lab50_tags(self):
# Three dummy files
# Four dummy files
open("foo.py", "w").close()
open("bar.py", "w").close()
open("baz.py", "w").close()
open("qux.py", "w").close()

# Dummy config file (.cs50.yml)
content = \
"lab50:\n" \
" files:\n" \
" - !open \"foo.py\"\n" \
" - !include \"bar.py\"\n" \
" - !exclude \"baz.py\"\n"
" - !exclude \"baz.py\"\n" \
" - \"qux.py\"\n"

# Create a config Loader for a tool called lab50
loader = lib50.config.Loader("lab50")

# Scope the files section of lab50 with the tags: open, include and exclude
loader.scope("files", "open", "include", "exclude")
loader.scope("files", "open", "include", "exclude", default="include")

# Load the config
config = loader.load(content)

# Figure out which files have an open tag
opened_files = [tagged_value.value for tagged_value in config.get("files") if tagged_value.tag == "open"]
opened_files = [tagged_value.value for tagged_value in config["files"] if tagged_value.tag == "open"]

# Have lib50.files figure out which files should be included and excluded
# Simultaneously ensure all open files exist
included, excluded = lib50.files(config.get("files"), require_tags=["open"])
included, excluded = lib50.files(config["files"], require_tags=["open"])

# Make sure that files tagged with open are also included
opened_files = [file for file in opened_files if file in included]

# Assert
self.assertEqual(included, {"foo.py", "bar.py"})
self.assertEqual(included, {"foo.py", "bar.py", "qux.py"})
self.assertEqual(excluded, {"baz.py"})
self.assertEqual(opened_files, ["foo.py"])
self.assertEqual(set(opened_files), {"foo.py"})


class TestLocal(unittest.TestCase):
Expand Down

0 comments on commit 7356e65

Please sign in to comment.