Skip to content

Commit

Permalink
Switch outdir to a keyward argument instead of positional
Browse files Browse the repository at this point in the history
  • Loading branch information
amstilp committed Jan 24, 2024
1 parent b18d9e6 commit c593735
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion primed/cdsa/management/commands/cdsa_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument(
"outdir",
"--outdir",
help="""Output directory where reports should be written. This directory will be created.""",
required=True,
)

def _export_table(self, table, filename):
Expand Down
20 changes: 11 additions & 9 deletions primed/cdsa/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def setUp(self):

def test_output(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
self.assertIn("generating reports... done!", out.getvalue())

def test_files_created(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
self.assertTrue(isdir(self.outdir))
self.assertTrue(isfile(os.path.join(self.outdir, "representative_records.tsv")))
self.assertTrue(isfile(os.path.join(self.outdir, "study_records.tsv")))
Expand All @@ -34,7 +34,7 @@ def test_files_created(self):

def test_representative_records_zero(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "representative_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 1)
Expand All @@ -44,14 +44,14 @@ def test_representative_records_three(self):
factories.DataAffiliateAgreementFactory.create()
factories.NonDataAffiliateAgreementFactory.create()
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "representative_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 4)

def test_study_records_zero(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "study_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 1)
Expand All @@ -61,14 +61,14 @@ def test_study_records_one(self):
signed_agreement__is_primary=True
)
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "study_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 2)

def test_cdsa_workspace_records_zero(self):
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "workspace_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 1)
Expand All @@ -77,7 +77,7 @@ def test_cdsa_workspace_records_one(self):
agreement = factories.DataAffiliateAgreementFactory.create()
factories.CDSAWorkspaceFactory.create(study=agreement.study)
out = StringIO()
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command("cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out)
with open(os.path.join(self.outdir, "workspace_records.tsv")) as f:
lines = f.readlines()
self.assertEqual(len(lines), 2)
Expand All @@ -86,5 +86,7 @@ def test_directory_exists(self):
os.mkdir(self.outdir)
out = StringIO()
with self.assertRaises(CommandError) as e:
call_command("cdsa_records", self.outdir, "--no-color", stdout=out)
call_command(
"cdsa_records", "--outdir", self.outdir, "--no-color", stdout=out
)
self.assertIn("already exists", str(e.exception))

0 comments on commit c593735

Please sign in to comment.