def test_get_part_filename_absolute_path_single_digit_day(self): with amending_settings(challenges_root=Path('/tmp/test-directory')): self.assertEqual( DefaultBoilerplate().get_part_filename(2020, 5, 'a'), Path('/tmp/test-directory/year_2020/day_05/part_a.py')) self.assertEqual( DefaultBoilerplate().get_part_filename(2020, 5, 'b'), Path('/tmp/test-directory/year_2020/day_05/part_b.py'))
def test_empty_directory(self): with tempfile.TemporaryDirectory() as challenges_root: with amending_settings( challenges_root=Path(challenges_root), challenges_boilerplate=DefaultBoilerplate()): current_year = datetime.now().year repo_info = RepoInfo.from_roots() self.assertFalse(repo_info.has_code) self.assertTrue( set(repo_info.year_infos).issuperset( {2015, 2016, 2017, 2018, 2019, 2020})) self.assertEqual(set(repo_info.year_infos), set(range(2015, current_year + 1))) for year, year_info in repo_info.year_infos.items(): self.assertEqual(year_info.year, year) self.assertFalse(year_info.has_code) self.assertFalse(year_info.path.exists()) self.assertEqual(set(year_info.day_infos), set(range(1, 26))) for day, day_info in year_info.day_infos.items(): self.assertEqual(day_info.year_info, year_info) self.assertEqual(day_info.year, year) self.assertEqual(day_info.day, day) self.assertFalse(day_info.has_code) self.assertFalse(day_info.path.exists()) self.assertEqual(set(day_info.part_infos), {'a', 'b'}) for part, part_info in day_info.part_infos.items(): self.assertEqual(part_info.day_info, day_info) self.assertEqual(part_info.year, year) self.assertEqual(part_info.day, day) self.assertEqual(part_info.part, part) self.assertFalse(part_info.has_code) self.assertFalse(part_info.path.exists())
def test_create_part_a_single_digit_day(self): files_in_repo_before_create = glob.glob(str( current_directory.joinpath('**/*')), recursive=True) with tempfile.TemporaryDirectory() as challenges_root: self.assertEqual( glob.glob(str(Path(challenges_root).joinpath('**/*')), recursive=True), []) with amending_settings(challenges_root=Path(challenges_root)): DefaultBoilerplate().create_part(2020, 5, 'a') self.assertEqual( set( glob.glob(str(Path(challenges_root).joinpath('**/*')), recursive=True)), { f"{challenges_root}/year_2020", f"{challenges_root}/year_2020/__init__.py", f"{challenges_root}/year_2020/day_05", f"{challenges_root}/year_2020/day_05/__init__.py", f"{challenges_root}/year_2020/day_05/part_a.py", f"{challenges_root}/year_2020/day_05/input.txt", }) files_in_repo_after_create = glob.glob(str( current_directory.joinpath('**/*')), recursive=True) self.assertEqual(files_in_repo_before_create, files_in_repo_after_create)
def creating_parts_on_disk(parts): with tempfile.TemporaryDirectory(dir=str(get_root_directory())) \ as challenges_root: challenges_module_name_root = Path(challenges_root).name extra_settings = { "challenges_root": Path(challenges_root), "challenges_boilerplate": DefaultBoilerplate(), "challenges_module_name_root": challenges_module_name_root, } with amending_settings(**extra_settings), \ resetting_modules(challenges_module_name_root): for part in parts: settings_proxy().challenges_boilerplate.create_part(*part) yield challenges_root
def test_paths_in_created_part_b_single_digit_day(self): with tempfile.TemporaryDirectory() as challenges_root: with amending_settings(challenges_root=Path(challenges_root)): boilerplate = DefaultBoilerplate() boilerplate.create_part(2020, 5, 'b') paths = set( map(str, ( boilerplate.get_part_filename(2020, 5, 'a'), boilerplate.get_part_filename(2020, 5, 'b'), boilerplate.get_day_directory(2020, 5), boilerplate.get_day_input_filename(2020, 5), boilerplate.get_year_directory(2020), ))) self.assertTrue( set( glob.glob(str(Path(challenges_root).joinpath('**/*')), recursive=True), ).issuperset(paths))
def test_some_parts_exist(self): with tempfile.TemporaryDirectory() as challenges_root: with amending_settings( challenges_root=Path(challenges_root), challenges_boilerplate=DefaultBoilerplate()): settings_proxy().challenges_boilerplate.create_part( 2020, 1, 'b') settings_proxy().challenges_boilerplate.create_part( 2020, 2, 'b') settings_proxy().challenges_boilerplate.create_part( 2020, 3, 'b') settings_proxy().challenges_boilerplate.create_part( 2020, 10, 'b') settings_proxy().challenges_boilerplate.create_part( 2020, 11, 'a') settings_proxy().challenges_boilerplate.create_part( 2019, 1, 'b') settings_proxy().challenges_boilerplate.create_part( 2019, 3, 'a') settings_proxy().challenges_boilerplate.create_part( 2019, 11, 'b') folder_contents = glob.glob(f"{challenges_root}/**/*", recursive=True) repo_info = RepoInfo.from_roots() self.assertTrue(repo_info.has_code) self.assertTrue( set(repo_info.year_infos).issuperset( {2015, 2016, 2017, 2018, 2019, 2020})) # Check years with code self.assertEqual( { year_info.year for year_info in repo_info.year_infos.values() if str(year_info.path) in folder_contents }, {2019, 2020}) self.assertEqual( { year_info.year for year_info in repo_info.year_infos.values() if year_info.has_code }, {2019, 2020}) self.assertEqual( { year_info.year for year_info in repo_info.year_infos.values() if year_info.path.exists() }, {2019, 2020}) # Check days with code self.assertEqual( {(day_info.year, day_info.day) for year_info in repo_info.year_infos.values() for day_info in year_info.day_infos.values() if str(day_info.path) in folder_contents}, { (2020, 1), (2020, 2), (2020, 3), (2020, 10), (2020, 11), (2019, 1), (2019, 3), (2019, 11), }) self.assertEqual( {(day_info.year, day_info.day) for year_info in repo_info.year_infos.values() for day_info in year_info.day_infos.values() if day_info.has_code}, { (2020, 1), (2020, 2), (2020, 3), (2020, 10), (2020, 11), (2019, 1), (2019, 3), (2019, 11), }) self.assertEqual( {(day_info.year, day_info.day) for year_info in repo_info.year_infos.values() for day_info in year_info.day_infos.values() if day_info.path.exists()}, { (2020, 1), (2020, 2), (2020, 3), (2020, 10), (2020, 11), (2019, 1), (2019, 3), (2019, 11), }) # Check parts with code self.assertEqual( {(part_info.year, part_info.day, part_info.part) for year_info in repo_info.year_infos.values() for day_info in year_info.day_infos.values() for part_info in day_info.part_infos.values() if str(part_info.path) in folder_contents}, { (2020, 1, 'a'), (2020, 1, 'b'), (2020, 2, 'a'), (2020, 2, 'b'), (2020, 3, 'a'), (2020, 3, 'b'), (2020, 10, 'a'), (2020, 10, 'b'), (2020, 11, 'a'), (2019, 1, 'a'), (2019, 1, 'b'), (2019, 3, 'a'), (2019, 11, 'a'), (2019, 11, 'b'), }) self.assertEqual( {(part_info.year, part_info.day, part_info.part) for year_info in repo_info.year_infos.values() for day_info in year_info.day_infos.values() for part_info in day_info.part_infos.values() if part_info.has_code}, { (2020, 1, 'a'), (2020, 1, 'b'), (2020, 2, 'a'), (2020, 2, 'b'), (2020, 3, 'a'), (2020, 3, 'b'), (2020, 10, 'a'), (2020, 10, 'b'), (2020, 11, 'a'), (2019, 1, 'a'), (2019, 1, 'b'), (2019, 3, 'a'), (2019, 11, 'a'), (2019, 11, 'b'), }) self.assertEqual( {(part_info.year, part_info.day, part_info.part) for year_info in repo_info.year_infos.values() for day_info in year_info.day_infos.values() for part_info in day_info.part_infos.values() if part_info.path.exists()}, { (2020, 1, 'a'), (2020, 1, 'b'), (2020, 2, 'a'), (2020, 2, 'b'), (2020, 3, 'a'), (2020, 3, 'b'), (2020, 10, 'a'), (2020, 10, 'b'), (2020, 11, 'a'), (2019, 1, 'a'), (2019, 1, 'b'), (2019, 3, 'a'), (2019, 11, 'a'), (2019, 11, 'b'), }) for year, year_info in repo_info.year_infos.items(): self.assertEqual(year_info.year, year) self.assertEqual(set(year_info.day_infos), set(range(1, 26))) for day, day_info in year_info.day_infos.items(): self.assertEqual(day_info.year_info, year_info) self.assertEqual(day_info.year, year) self.assertEqual(day_info.day, day) self.assertEqual(set(day_info.part_infos), {'a', 'b'}) for part, part_info in day_info.part_infos.items(): self.assertEqual(part_info.day_info, day_info) self.assertEqual(part_info.year, year) self.assertEqual(part_info.day, day) self.assertEqual(part_info.part, part)
Do not put your session ID here, so that you don't run the risk of committing the file to Git! Put it in `sensitive_user_settings.py` in the same directory. """ CHALLENGES_ROOT = repo_root """ The directory where the challenges code is on. """ CHALLENGES_MODULE_NAME_ROOT = None """ The name of the module under which the challenges leave. If there is no parent module (or it is the root one) you can leave it as `None`. """ CHALLENGES_BOILERPLATE = DefaultBoilerplate( example_part_path=repo_root.joinpath('custom', 'custom_example_part.py'), ) """ The name of the class that knows where individual challenges are on the disk, and knows how to create them. This can be either a class, or the full class name, or an instance """ SITE_DATA_PATH = dot_aox.joinpath('site_data.json') """ The path for the cached data from the AOC site - this helps remember how many stars you have, and also which challenges have you completed. This needs to be a `Path` instance. """
def test_get_part_module_name_custom_package_double_digit_day(self): with amending_settings(challenges_module_name_root='custom.package'): self.assertEqual( DefaultBoilerplate().get_part_module_name(2020, 15, 'a'), 'custom.package.year_2020.day_15.part_a')
def test_get_part_module_name_top_level_double_digit_day(self): with amending_settings(challenges_module_name_root=None): self.assertEqual( DefaultBoilerplate().get_part_module_name(2020, 15, 'a'), 'year_2020.day_15.part_a')
def test_get_year_directory_absolute_path(self): with amending_settings(challenges_root=Path('/tmp/test-directory')): self.assertEqual(DefaultBoilerplate().get_year_directory(2020), Path('/tmp/test-directory/year_2020'))
def test_get_day_directory_absolute_path_double_digit_day(self): with amending_settings(challenges_root=Path('/tmp/test-directory')): self.assertEqual(DefaultBoilerplate().get_day_directory(2020, 15), Path('/tmp/test-directory/year_2020/day_15'))